Click here to Skip to main content
13,287,116 members (42,038 online)
Click here to Skip to main content
Add your own
alternative version


71 bookmarked
Posted 6 Jan 2006

Compress your ASP.NET 2.0 pages

, 1 Feb 2006
Rate this:
Please Sign up or sign in to vote.
An article on how to zip the output stream of an ASP.NET page.

A screenshot of the trace


To be on the web with a website that is half successful, you can feel in your wallet pretty quickly. The bandwidth is often a cost factor in the price of a website. Limiting that bandwidth is possible through a few compression standards. I was looking for a way on how to compress my ASP.NET pages when I found the module of Ben Lowery which can be found here. But his implementation never worked properly, not in .NET 1.1 and not in .NET 2.0, at least not in my case.

I downloaded his code and had a read through it, and it was completely .NET 1.1 style and still written like it was using the #ziplib. So, I rewrote his version to something that does work properly and also detects the path properly. In my case, whenever I tried to use his library, the output of my pages was empty.

Using the code

To use the code is pretty easy. Once you've compiled the HttpCompress module, you can add a reference to any .NET 2.0 site. Next, you should set a few parameters in the web.config and you're good to go. If you want to see whether the content is really filtered, you will need something that logs the HTTP pipeline. I use Nikhil Kothari's WebDevHelper BHO to do it. An alternative would be to use Fiddler.

The first thing you can configure are paths and mime-types that are to be excluded from being compressed by the module. I, for one, do not compress any images nor do I compress streaming video etc. because these formats have already been compressed pretty good and you won't be gaining anything significant by compressing them. You are more likely to use more server resources for a small gain.

    <sectionGroup name="Flanders">
      <section name="HttpCompress" 

                 Configuration, HttpCompress"/>
    <HttpCompress compressionType="GZip">
        <add path="NoCompression.aspx"/>
        <add mime="image/jpeg"/>
      <add name="HttpCompressModule" 


In the module, you need to hook up an event to the PostReleaseRequeststate. Before, I used to hook it up to the BeginRequest event but this executes way too early for the module to execute. At PostReleaseRequestState, the whole page has executed and its response content has been generated.

41         public void Init(HttpApplication context)
42         {
43             context.PostReleaseRequestState+=
                    new EventHandler(context_PostReleaseRequestState);
44         }


  • 07/01/2006: v.1.0 - Added content to CodeProject and wrote this article.
  • 23/01/2006: v.1.1 - Refactored the module because of problems with JavaScript handling and many more ;-).


This article, along with any associated source code and files, is licensed under The MIT License


About the Author

Casual Jim
Software Developer (Senior)
Belgium Belgium
No Biography provided

You may also be interested in...

Comments and Discussions

General'context_PostReleaseRequestState' does not exist in the current context Pin
richard.tchicou5-Jan-09 1:56
memberrichard.tchicou5-Jan-09 1:56 
GeneralNot happy Pin
smilysanjai6-Oct-08 21:51
membersmilysanjai6-Oct-08 21:51 
GeneralRe: Not happy Pin
Casual Jim6-Oct-08 23:11
memberCasual Jim6-Oct-08 23:11 
GeneralRe: Not happy Pin
smilysanjai6-Oct-08 23:57
membersmilysanjai6-Oct-08 23:57 
GeneralRe: Not happy Pin
Casual Jim7-Oct-08 0:22
memberCasual Jim7-Oct-08 0:22 
GeneralRe: Not happy Pin
smilysanjai7-Oct-08 1:17
membersmilysanjai7-Oct-08 1:17 
GeneralRe: Not happy Pin
Casual Jim7-Oct-08 1:26
memberCasual Jim7-Oct-08 1:26 
GeneralRe: Not happy Pin
Casual Jim6-Oct-08 23:12
memberCasual Jim6-Oct-08 23:12 
GeneralRe: Not happy Pin
smilysanjai7-Oct-08 2:56
membersmilysanjai7-Oct-08 2:56 
GeneralRe: Not happy Pin
Casual Jim7-Oct-08 3:05
memberCasual Jim7-Oct-08 3:05 
GeneralRe: Not happy Pin
smilysanjai7-Oct-08 3:13
membersmilysanjai7-Oct-08 3:13 
GeneralRe: Not happy Pin
Casual Jim7-Oct-08 3:47
memberCasual Jim7-Oct-08 3:47 
GeneralRe: Not happy Pin
Casual Jim7-Oct-08 3:48
memberCasual Jim7-Oct-08 3:48 
GeneralRe: Not happy Pin
smilysanjai7-Oct-08 23:34
membersmilysanjai7-Oct-08 23:34 
GeneralRe: Not happy Pin
Casual Jim8-Oct-08 0:10
memberCasual Jim8-Oct-08 0:10 
GeneralRe: Not happy Pin
smilysanjai21-Oct-08 0:40
membersmilysanjai21-Oct-08 0:40 
GeneralRe: Not happy Pin
Casual Jim21-Oct-08 0:43
memberCasual Jim21-Oct-08 0:43 
GeneralRe: Not happy Pin
smilysanjai21-Oct-08 4:06
membersmilysanjai21-Oct-08 4:06 
GeneralRe: Not happy Pin
mercede14-Oct-11 7:15
membermercede14-Oct-11 7:15 
GeneralRe: Not happy Pin
Smart_Boy26-Jan-12 4:28
memberSmart_Boy26-Jan-12 4:28 
GeneralAjax Problem Pin
returnofjedi23-Aug-07 3:10
memberreturnofjedi23-Aug-07 3:10 
GeneralWebResource.axd Pin
ecellcell30-Nov-06 9:58
memberecellcell30-Nov-06 9:58 
GeneralResponse.WriteSubstitution Does not work Pin
GFunny197210-Nov-06 8:39
memberGFunny197210-Nov-06 8:39 
GeneralRe: Response.WriteSubstitution Does not work Pin
Casual Jim10-Nov-06 9:20
memberCasual Jim10-Nov-06 9:20 
GeneralRe: Response.WriteSubstitution Does not work Pin
GFunny197213-Nov-06 5:07
memberGFunny197213-Nov-06 5:07 
Its called Post Cache Substituion -[^

It allows you to cache a page or control but still keep one portion of the page dynamic. When using the HTTPCompress, it doesn't execute the page/control code for the dynamic portion of the page it simply caches the whole page. What I have done for now is excluded the pages that use it for now.
Generalhttpcompress and focus() Event Pin
gablersoftware10-May-06 3:18
membergablersoftware10-May-06 3:18 
GeneralRe: httpcompress and focus() Event Pin
Casual Jim10-May-06 11:30
memberCasual Jim10-May-06 11:30 
GeneralRe: httpcompress and focus() Event Pin
gablersoftware11-May-06 22:05
membergablersoftware11-May-06 22:05 
GeneralCompression While Posting Back... Pin
alidehghan6-Feb-06 22:00
memberalidehghan6-Feb-06 22:00 
GeneralRe: Compression While Posting Back... Pin
Casual Jim7-Feb-06 9:13
memberCasual Jim7-Feb-06 9:13 
GeneralCSS & JS Includes Pin
joeyb10003-Feb-06 4:30
memberjoeyb10003-Feb-06 4:30 
GeneralRe: CSS & JS Includes Pin
Casual Jim7-Feb-06 9:04
memberCasual Jim7-Feb-06 9:04 
QuestionHow I check up that "output stream of an ASP.NET page" is done? Pin
Dolonk24-Jan-06 22:17
memberDolonk24-Jan-06 22:17 
AnswerRe: How I check up that "output stream of an ASP.NET page" is done? Pin
Casual Jim24-Jan-06 23:26
memberCasual Jim24-Jan-06 23:26 
QuestionMedium trust? Pin
aerodave22-Jan-06 20:33
memberaerodave22-Jan-06 20:33 
GeneralJavascript nasties Pin
vaticnz11-Jan-06 10:15
membervaticnz11-Jan-06 10:15 
GeneralRe: Javascript nasties Pin
Casual Jim22-Jan-06 17:05
memberCasual Jim22-Jan-06 17:05 
GeneralRe: Javascript nasties Pin
ahoja7-Feb-06 23:48
memberahoja7-Feb-06 23:48 
QuestionWhat kind of files should be excluded? Pin
MorningZ10-Jan-06 7:04
memberMorningZ10-Jan-06 7:04 
AnswerRe: What kind of files should be excluded? Pin
Casual Jim10-Jan-06 9:49
memberCasual Jim10-Jan-06 9:49 
GeneralFailing in IE6 Pin
aerodave9-Jan-06 13:34
memberaerodave9-Jan-06 13:34 
GeneralRe: Failing in IE6 Pin
Casual Jim10-Jan-06 10:03
memberCasual Jim10-Jan-06 10:03 
GeneralRe: Failing in IE6 Pin
Casual Jim22-Jan-06 17:08
memberCasual Jim22-Jan-06 17:08 
GeneralRe: Failing in IE6 Pin
aerodave22-Jan-06 20:31
memberaerodave22-Jan-06 20:31 
GeneralRe: Failing in IE6 Pin
Neetflash23-May-06 17:08
memberNeetflash23-May-06 17:08 
GeneralIIS Compression Pin
Jon Sagara6-Jan-06 14:46
memberJon Sagara6-Jan-06 14:46 
GeneralRe: IIS Compression Pin
Casual Jim6-Jan-06 14:58
memberCasual Jim6-Jan-06 14:58 
GeneralRe: IIS Compression Pin
Joshua Lunsford8-Jan-06 12:39
memberJoshua Lunsford8-Jan-06 12:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171207.1 | Last Updated 1 Feb 2006
Article Copyright 2006 by Casual Jim
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid