Use Filter to compress the asp.net page

Source: Internet
Author: User
            if (!Request.UserAgent.ToLower().Contains("konqueror"))            {                if (Request.Headers["Accept-encoding"] != null &&                   Request.Headers["Accept-encoding"].Contains("gzip"))                {                    Response.Filter = new GZipStream(Response.Filter,                                      CompressionMode.Compress, true);                    Response.AppendHeader("Content-encoding", "gzip");                }                else if (Request.Headers["Accept-encoding"] != null &&                        Request.Headers["Accept-encoding"].Contains("deflate"))                {                    Response.Filter = new DeflateStream(Response.Filter,                                      CompressionMode.Compress, true);                    Response.AppendHeader("Content-encoding", "deflate");                }            }
This code disconnection was accidentally found on the codeproject. It feels very good and I would like to share it with you. Request. userAgent. toLower (). contains ("konqueror") is used to filter out the konqueror browser. According to the original author, this browser may not support gzip and deflate well and has bugs. Here I also found a problem. If Response. BufferOutput is set to false, this code disconnection is not easy to use. You should pay attention to it when using it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.