Can gzip compression be selectively disabled in ASP.NET/IIS 7?

前端 未结 3 822
长情又很酷
长情又很酷 2020-12-02 15:17

I am using a long-lived asynchronous HTTP connection to send progress updates to a client via AJAX. When compression is enabled, the updates are not received in discrete ch

3条回答
  •  臣服心动
    2020-12-02 15:23

    I found a much easier way to do this. Instead of selectively doing your own compression, you can selectively disable the default IIS compression (assuming its enabled in your web.config).

    Simply remove the accept-encoding encoding header on the request and IIS wont compress the page.

    (global.asax.cs:)

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        try
        {
            HttpContext.Current.Request.Headers["Accept-Encoding"] = "";
        }
        catch(Exception){}
    }
    

提交回复
热议问题