The communication between Server and Client is carried out via HTTP messages by sending necessary data. The workload of server and net speed is exactly how much time this messages requires to be sent. Therefore, to decrease message ( by using compressing algorithm and techniques ) size means higher speed and efficient bandwidth. Almost all new browsers can use "gzip" and "deflate" compression algorithms. ( they can decompress messages that comes from server) ASP.NET gives us compressing ability.

We will use "HttpModule" in this article. First create a Windows Class Library in C#.

Note: HttpModule' s are the controls that manipulates Request and Response messages. 



Name project as "CompressionModule" and with same name add a new class. Right-Click to the project, select "Add Reference" , browse "System.Web". Then write below code  :
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Web;  
  
namespace ZipModule  
{  
    //to get HttpModule capabilities implement "IHttpModule" interface
  
    public class CompressionModule : IHttpModule    
    {  
 
        #region IHttpModule Members  
  
        public void Dispose()  
        {  
            throw new NotImplementedException();  
        }  
  
        public void Init(HttpApplication context)  
        {  
            context.BeginRequest += new EventHandler(context_BeginRequest);  
        //besides default event handler we should write our custom one
        //context -->> current application that invokes our HttpModule
        }  
  
        void context_BeginRequest(object sender, EventArgs e)  
        {  
            HttpApplication app = (HttpApplication)sender;  
        //name this application as sender
  
            string encodings = app.Request.Headers.Get("Accept-Encoding");  
        //"Accept-Encoding" is the Http Header that informs us
        //whether the browser can use encoding algorithms
  
            if (encodings == null) //if it can't return
                return;  
  
            Stream s = app.Response.Filter;  
        //if can filter the response message
  
            encodings = encodings.ToLower();  
  
            if (encodings.Contains("gzip"))  
            {  
                app.Response.Filter = new GZipStream(s, CompressionMode.Compress);  
            //here is the core of the code
	//we zip the code here  
              
                app.Response.AppendHeader("Compression Tecnique", "gzip");  
            //we add a header to message so that we will be able
            //trace whether our module is working or not
          
                app.Context.Trace.Warn("GZIP Compression on");  
            }  
  
            else  
            {  
                app.Response.Filter = new DeflateStream(s, CompressionMode.Compress);  
            //if browser can't use "gzip" compress the message 
	//with "deflate"  
              
                app.Response.AppendHeader("Content-Encoding", "deflate");  
                app.Context.Trace.Warn("Deflate compression on");  
            }  
  
        }  
 
        #endregion  
    }  
}  
Build the project, copy the "ZipModule.dll" from "bin" directory. Add this .dll to your new website. Again like we did above right-click the website name and browse the "ZipModule.dll" and select it. To use this HttpModule we should configure "web.config" :
<httpModules>
    <add name="HttpCompressionModule" type="ZipModule.CompressionModule"/>
</httpModules>
<trace enabled="true"/>

By writing "<trace enabled="true"/>" we can trace our application and see exactly what happens in Request and Response messages. After making above configuration settings our HttpModule should work and compress the Http Messages. In browser url part, write "../Default.aspx/trace.axd". Click "View Details", if you see "Gzip compression on" ( like below snapshot ) then your HttpModule is working and you can send compressed Http Messages.  Congratulations.....