Pergunta

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.

Foi útil?

Solução

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

Outras dicas

Actually you can install a nuget package to achieve that, this requires little configuration, in client side you just need to add the accept-encoding:gzip.

Using this approach is better these days when ASP.Net is able to run in any Web Server.

In this video I have a full / complete explanation of WebApi using gzip compression. Is in spanish, but you know "Code is an universal language"

NinjaTip #16 | Incluyendo soporte para GZip en WebAPI | C# NinjaTip #16 | Incluyendo soporte para GZip en WebAPI

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top