11

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.

Community
  • 1
  • 1
Carvellis
  • 3,992
  • 2
  • 34
  • 66
  • Is dynamic compression enabled for mimetype 'application/json; charset=utf-8'? By default this is not enabled even if dynamic compression is enabled – Eivind T Jul 19 '12 at 11:50
  • @EivindT how can I check that? – Carvellis Jul 21 '12 at 12:40
  • 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: http://stackoverflow.com/a/7375645/243936 – Eivind T Jul 21 '12 at 19:46
  • Cool, that works! If you'll post this as an answer I will accept it. – Carvellis Jul 22 '12 at 18:33

2 Answers2

11

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

Community
  • 1
  • 1
Eivind T
  • 1,059
  • 9
  • 14
  • 1
    I had no problem editing the applicationhost.config file manually using notepad. All you need to add is one line to the httpCompression -> dynamicTypes section: ``. See this link for more details: http://benfoster.io/blog/aspnet-web-api-compression Once I did that, my web api responses were gzipped. – goku_da_master Feb 23 '16 at 23:45
0

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

JuanK
  • 2,056
  • 19
  • 32