Verify that this is an acceptable HttpCompression module?

Posted on 2010-01-09
Medium Priority
Last Modified: 2013-12-17
Hello experts.

I am attempting to improve performance on my site.  I am writing my own http compression module, and I just basically need a few opinions on whether or not this is an acceptable approach.

I am using a lot of Microsoft Ajax on my site (just the stuff that comes with Visual Studio, nothing fancy like Telerik or 3rd party controls)

When I engage this httpModule in my web config, it considerably drops the size of data transfer on each initial page load and ALSO on each subsequent ajax call.  It would appear that everything is working fine.  However, I am kind of feeling that this is too easy, and that I am perhaps missing something very important.  

Please review the below code and give me your thoughts.  Thank you!
public class HttpCompressionModule: IHttpModule
        public void Dispose()


        public void Init(HttpApplication application)
            application.BeginRequest += new EventHandler(context_BeginRequest);

        void context_BeginRequest(object sender, EventArgs e)
            HttpApplication app = (HttpApplication)sender;

            string currentPath = app.Request.CurrentExecutionFilePath;
            string ext = Path.GetExtension(currentPath).ToLower();

            switch (ext)
                case ".axd":

            // Accepted encodings
            string encodings = app.Request.Headers.Get("Accept-Encoding");

            // No encodings; stop HTTP Module processing
            if (string.IsNullOrEmpty(encodings))

            // Current response stream
            Stream baseStream = app.Response.Filter;

            // Determine the requested encoding
            if (encodings.Contains("gzip"))
                app.Response.Filter = new GZipStream(baseStream, CompressionMode.Compress);
                app.Response.AppendHeader("Content-Encoding", "gzip");
            else if (encodings.Contains("deflate"))
                app.Response.Filter = new DeflateStream(baseStream, CompressionMode.Compress);
                app.Response.AppendHeader("Content-Encoding", "deflate");

Open in new window

Question by:Gewgala

Accepted Solution

Deathrace earned 2000 total points
ID: 26277396
Nice try, one more article to help you

Author Closing Comment

ID: 31675060

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question