Click here to Skip to main content
Click here to Skip to main content

Compress Aspx with GZip

, 7 May 2009 GPL3
Rate this:
Please Sign up or sign in to vote.
A simple function to compress aspx page


This is a simple function to compress your aspx page with GZip.


If you need advanced knowledge about compression, please visit this link.

Using the Code

Just call this function in the page render: 

protected override void Render(HtmlTextWriter writer)

The method:

public static void doCompression()
      HttpContext context = HttpContext.Current;
      HttpRequest request = context.Request;
      string acceptEncoding = request.Headers["Accept-Encoding"];
      HttpResponse response = context.Response;
      if (!string.IsNullOrEmpty(acceptEncoding))
           acceptEncoding = acceptEncoding.ToUpperInvariant();
           response.Filter = new GZipStream(context.Response.Filter, 
           if (acceptEncoding.Contains("GZIP"))
           else if (acceptEncoding.Contains("DEFLATE"))
           response.Cache.VaryByHeaders["Accept-Encoding"] = true;           


  • 7th May, 2009: Initial post


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Mohamed Magdy (Medo)
Web Developer
Egypt Egypt
No Biography provided

Comments and Discussions

GeneralAnother big bug Pinmemberal13n9-Jan-10 1:14 
GeneralIncorrect Caching PinmemberMember 451353918-May-09 11:15 
General[My vote of 2] There is a big bug in the code Pinmemberkatrash13-May-09 4:29 
GeneralSlower than CompressModule Pinmembercecildt12-May-09 4:25 
QuestionUnzip Pinmemberstixoffire11-May-09 23:20 
AnswerRe: Unzip PinmemberMohamed Magdy (Medo)18-May-09 7:03 
GeneralNeat trick if you can't get access to IIS PinmemberMatware11-May-09 20:49 
GeneralIncomplete!!!! Pinmemberzlezj8-May-09 2:42 
GeneralRe: Incomplete!!!! PinmemberMohamed Magdy (Medo)11-May-09 2:11 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141220.1 | Last Updated 7 May 2009
Article Copyright 2009 by Mohamed Magdy (Medo)
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid