Search code examples
asp.net-mvcgzipasp.net-mvc-4asp.net-web-apihttp-compression

MVC4 WebAPI not compressing GET responses


I'm working on a project that uses the MVC4 WebAPI (RC). The responses are not gzip compressed (dynamic compression in IIS is enabled).

The responses from normal MVC controllers are compressed. Do I need a specific setting to enable gzip compression for WebAPI responses?

I could add a custom compression handler, but if possible, I would just like to use the built-in IIS compression.

BTW, I know this is almost a duplicate of Compress HTTP GET Response, however the accepted answer there doesn't really answer my question.


Solution

  • Is dynamic compression enabled for mimetype application/json; charset=utf-8? By default this is not enabled even if dynamic compression is enabled.

    To see if it is enabled, you can look in the applicationhost.config file under %windir%\System32\inetsrv\config in the section.

    You should not edit the file, instead use appcmd.exe to change it like this: https://stackoverflow.com/a/7375645/243936