How can I get ASP.NET AJAX to send its JSON response with GZip compression?

前端 未结 4 593
囚心锁ツ
囚心锁ツ 2021-02-05 19:35

I have compression enabled within IIS7 and it works as expected on all responses except for those constructed by ASP.NET AJAX. I have a web service that provides data to the cl

4条回答
  •  余生分开走
    2021-02-05 20:19

    IIS7 uses the content-encoding to decide whether to compress the response (assuming of course that the browser can accept gzip). They're set in applicationHost.config, and by default the list is

    
         
         
         
         
    
    

    If you call the web service directly, the XML response has a content-type of text/xml, which gets compressed. When called by AJAX, the JSON response has a content type of application/json, so it isn't compressed. Adding the following to applicationHost.config should fix that...

         
    

提交回复
热议问题