How to enable gzip HTTP compression on Windows Azure dynamic content

前端 未结 6 776
不知归路
不知归路 2020-12-04 06:55

I\'ve been trying unsuccessfully to enable gzip HTTP compression on my Windows Azure hosted WCF Restful service which returns JSON only from GET and POST requests.

6条回答
  •  生来不讨喜
    2020-12-04 07:21

    Well it took a very long time ... but I have finally solved this, and I want to post the answer for anyone else who is struggling. The solution is very simple and I've verified that it does definitely work!!

    Edit your ServiceDefinition.csdef file to contain this in the WebRole tag:

        
          
        
    

    In your web-role, create a text file and save it as "EnableCompression.cmd"

    EnableCompression.cmd should contain this:

    %windir%\system32\inetsrv\appcmd set config /section:urlCompression /doDynamicCompression:True /commit:apphost
    %windir%\system32\inetsrv\appcmd set config  -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='True']" /commit:apphost
    

    .. and that's it! Done! This enables dynamic compression for the json returned by the web-role, which I think I read somewhere has a rather odd mime type, so make sure you copy the code exactly.

提交回复
热议问题