Search code examples
asp.net-mvcazureweb-configgziphttp-compression

JSON compression not working on Azure


I'm working on an MVC5 web app but can't make Azure perform dynamic compression on my JsonResults. The following code in my Web.config only works when I run the web app locally, but as soon as I deploy on Azure Web App the compression does not work:

<urlCompression doStaticCompression="true" doDynamicCompression="true" />
<httpCompression>
  <dynamicTypes>
    <add mimeType="application/json" enabled="true" />
    <add mimeType="application/json; charset=utf-8" enabled="true" />
  </dynamicTypes>
  <staticTypes>
    <add mimeType="application/json" enabled="true" />
    <add mimeType="application/json; charset=utf-8" enabled="true" />
  </staticTypes>
</httpCompression>

I also tried the following, but with no luck:

<urlCompression doStaticCompression="true" doDynamicCompression="true" />
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
  <dynamicTypes>
    <add mimeType="application/json" enabled="true" />
    <add mimeType="application/json; charset=utf-8" enabled="true" />
  </dynamicTypes>
  <staticTypes>
    <add mimeType="application/json" enabled="true" />
    <add mimeType="application/json; charset=utf-8" enabled="true" />
  </staticTypes>
</httpCompression>

This issue is really driving me crazy, I see no reason why this shouldn't work, considering that I found these solutions online from people who says that they implemented them successfully. Any idea?


Solution

  • I finally got what the problem was: some antiviruses (including mine, which is Bitdefender) interfere with the data compression mechanism, so from my computer I couldn't see the compression happening, while in reality it was working perfectly using the following Web.config markup:

    <urlCompression doStaticCompression="true" doDynamicCompression="true" />
    <httpCompression>
      <dynamicTypes>
        <add mimeType="application/json" enabled="true" />
        <add mimeType="application/json; charset=utf-8" enabled="true" />
      </dynamicTypes>
      <staticTypes>
        <add mimeType="application/json" enabled="true" />
        <add mimeType="application/json; charset=utf-8" enabled="true" />
      </staticTypes>
    </httpCompression>
    

    For more info about similar issues, here is an interesting article about it: https://www.stevesouders.com/blog/2009/11/11/whos-not-getting-gzip/