How to compress Json result from ASP.NET MVC using IIS 7.5

I find it hard to get IIS 7 to properly compress the Json result from ASP.NET MVC. I have enabled static and dynamic compression in IIS. I can verify with Fiddler that plain text / html and similar entries are compressed. When viewing the request, the gzip accept-encoding header is present. The response has mimetype "application / json" but is not compressed.

I found that the problem is related to MimeType. When I turn on mimeType="*/*" , I see that the answer is correctly gzipped. How do I get IIS to compress without using wildcard mimeType? I assume this issue has something to do with how ASP.NET MVC generates content type headers.

CPU utilization is well below the dynamic throttling threshold. When I look at the trace logs from IIS, I see that it is not compressed due to the lack of a suitable mime type.

 <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" noCompressionForProxies="false"> <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" /> <dynamicTypes> <add mimeType="text/*" enabled="true" /> <add mimeType="message/*" enabled="true" /> <add mimeType="application/x-javascript" enabled="true" /> <add mimeType="application/json" enabled="true" /> </dynamicTypes> <staticTypes> <add mimeType="text/*" enabled="true" /> <add mimeType="message/*" enabled="true" /> <add mimeType="application/x-javascript" enabled="true" /> <add mimeType="application/atom+xml" enabled="true" /> <add mimeType="application/xaml+xml" enabled="true" /> <add mimeType="application/json" enabled="true" /> </staticTypes> </httpCompression> 
+55
json asp.net-mvc iis-7
Jan 26
source share
4 answers

Make sure your % WinDir% \ System32 \ inetsrv \ config \ applicationHost.config contains the following data:

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

From the link @AtanasKorchev.

As @simon_weaver explained in the comments, you can edit the wrong file with a 32-bit editor on 64-bit Windows, use notepad.exe to make sure that this file is really modified.

+56
May 10 '12 at 7:07
source share

I have successfully used the dedicated approach here .

+21
Jan 26 '10 at 8:52
source share

Use this manual

None of these answers worked for me. I took note of the / json application ; charset = utf-8 mime-type.

+14
Jun 19 '12 at 3:12
source share

I recommend this approach.
Create a CompressAttribute class and set the target action.

+5
Jan 26
source share



All Articles