0

i saw people just detect that requesting browser support http compression or not. if support then detect support gzip or deflate.

and then just add attribute to response object like

HttpContext.Current.Response.AppendHeader("Content-encoding", "gzip");

or

HttpContext.Current.Response.AppendHeader("Content-encoding", "deflate");

i just need to know who actually comresee the response. is it webserver or asp.net worker process. please duscuss in detail who and how compress the response. thanks

1 Answer 1

1

Actually the header that you show here is not make the compression. What make the compression is a Stream Class that you set on Response.Filter and this compression is made by Asp.Net something like:

    if (acceptEncoding.Contains("gzip"))
    {
        // gzip
        app.Response.Filter = new GZipStream(prevUncompressedStream, CompressionMode.Compress);
        app.Response.AppendHeader("Content-Encoding", "gzip");
    }       
    else if (acceptEncoding.Contains("deflate") || acceptEncoding == "*")
    {
        // deflate
        app.Response.Filter = new DeflateStream(prevUncompressedStream, CompressionMode.Compress);
        app.Response.AppendHeader("Content-Encoding", "deflate");
    }       

If you made this then the compression is done by asp.net and NOT by IIS. The iis then detect that the file is all ready compressed and not compressed again. Some times I have see that this detection fails and the page is not show at all, so in this case you deactivate the iis compression.

Here is the gZipStream Class that is inside asp.net http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx

So the asp.net worked process made the compression, if you set the GZipStream, of the DeflateStream

Here is an example of file compression by asp.net using GZipStream http://www.dotnetperls.com/gzipstream

I prefer to make the compression on asp.net and not on iis, because I have more control on it.

Sign up to request clarification or add additional context in comments.

3 Comments

IIS compression is better or asp.net compression is better. which one can make more compress output.
@user750398 gZip is the better and the default, but you do not decide, you ask the browser to select whats prefer using the acceptEncoding value
@user750398 its better to make the compression on asp.net because you have totally control, eg the flush is working on asp.net but not on iis, for example if you won to send a part of your page, you flush it, until the rest of the page get ready. Also if you make it on asp.net you can select or even change the gZip compression.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.