Previous Next

Thread: Response compression doesn't work IIS 6

Last post 08-04-2008 10:16 PM by steve schofield. 1 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (2 items)

Sort Posts:

  • 08-04-2008, 2:09 PM

    • yoyoseek
    • Not Ranked
    • Joined on 06-15-2007, 8:20 AM
    • Posts 1
    • yoyoseek

    Response compression doesn't work IIS 6

    HI to all.

    In my ASP.NET web-application I use the following code in order to compress some response:

            public bool IsGZipSupported()
            {
                string AcceptEncoding = HttpContext.Current.Request.Headers["Accept-Encoding"];
                if (!string.IsNullOrEmpty(AcceptEncoding) &&
                   (AcceptEncoding.Contains("gzip") || AcceptEncoding.Contains("deflate")))
                    return true;

                return false;
            }

            public void GZipEncodePage()
            {
                if (IsGZipSupported())
                {
                    HttpResponse Response = HttpContext.Current.Response;

                    string AcceptEncoding = HttpContext.Current.Request.Headers["Accept-Encoding"];

                    if (AcceptEncoding.Contains("gzip"))
                    {
                        Response.Filter = new System.IO.Compression.GZipStream(Response.Filter,
                                     System.IO.Compression.CompressionMode.Compress);
                        Response.AppendHeader("Content-Encoding", "gzip");

                    }
                    else
                    {
                        Response.Filter = new System.IO.Compression.DeflateStream(Response.Filter,
                                     System.IO.Compression.CompressionMode.Compress);
                        Response.AppendHeader("Content-Encoding", "deflate");

                    }
                }
            }

            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);

                GZipEncodePage();
            }

    It works perfect under IIS 5.1 and doesn't work under IIS 6. I view header of this HTTP response and don't find Contet-Encoding key. What the reason?

  • 08-04-2008, 10:16 PM In reply to

    Re: Response compression doesn't work IIS 6

    IIS could be uncompressing maybe?  Is IIS compression disabled on the server?

    Steve Schofield
    Windows Server MVP - IIS
    MCTS - Windows Hosting

    http://weblogs.asp.net/steveschofield
    http://www.iislogs.com
    http://www.orcsweb.com/
    Managed Hosting Solutions
    #1 in Service and Support
Page 1 of 1 (2 items)
Page view counter