I'm having difficulty making IIS 7 correctly compress a Json result from ASP.NET MVC. I've enabled static and dynamic compression in IIS. I can verify with Fiddler that normal text/html and similar records are compressed. Viewing the request, the accept-encoding gzip header is present. The response has the mimetype "application/json", but is not compressed.
我很难使iis7正确地从ASP中压缩Json结果。净MVC。我在IIS中启用了静态和动态压缩。我可以用Fiddler验证正常的文本/html和类似的记录被压缩。查看请求时,接受编码gzip报头。响应具有mimetype“应用程序/json”,但没有被压缩。
I've identified that the issue appears to relate to the MimeType. When I include mimeType="*/*"
, I can see that the response is correctly gzipped. How can I get IIS to compress WITHOUT using a wildcard mimeType? I assume that this issue has something to do with the way that ASP.NET MVC generates content type headers.
我发现这个问题似乎与MimeType有关。当我包含mimeType="*/*"时,我可以看到响应被正确地压缩了。如何在不使用通配符mimeType的情况下让IIS进行压缩?我认为这个问题与ASP的方式有关。NET MVC生成内容类型标题。
The CPU usage is well below the dynamic throttling threshold. When I examine the trace logs from IIS, I can see that it fails to compress due to not finding a matching mime type.
CPU使用率远低于动态节流阈值。当我检查来自IIS的跟踪日志时,我可以看到它由于没有找到匹配的mime类型而无法压缩。
<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>
4 个解决方案
#1
58
Make sure your %WinDir%\System32\inetsrv\config\applicationHost.config contains these:
确保你的%列出% \ System32系统\ inetsrv \ config \ applicationHost。配置包含这些:
<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 of @AtanasKorchev.
@AtanasKorchev的链接。
As @simon_weaver said in the comments, you might be editing the wrong file with a 32 bit editor on a 64 bit Windows, use notepad.exe to make sure this file is indeed modified.
正如@simon_weaver在评论中说的,您可能正在编辑错误的文件,在64位Windows上使用32位编辑器,使用记事本。exe确保该文件确实被修改。
#3
14
使用本指南
None of these answers worked for me. I did take note of the application/json; charset=utf-8 mime-type though.
这些回答对我都不起作用。我确实注意到了应用程序/json;utf - 8字符集= mime类型。
#4
5
I recommend this approach
Create CompressAttribute
class, and set target action.
我推荐这一方法创建CompressAttribute类,并设置目标操作。
#1
58
Make sure your %WinDir%\System32\inetsrv\config\applicationHost.config contains these:
确保你的%列出% \ System32系统\ inetsrv \ config \ applicationHost。配置包含这些:
<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 of @AtanasKorchev.
@AtanasKorchev的链接。
As @simon_weaver said in the comments, you might be editing the wrong file with a 32 bit editor on a 64 bit Windows, use notepad.exe to make sure this file is indeed modified.
正如@simon_weaver在评论中说的,您可能正在编辑错误的文件,在64位Windows上使用32位编辑器,使用记事本。exe确保该文件确实被修改。
#2
#3
14
使用本指南
None of these answers worked for me. I did take note of the application/json; charset=utf-8 mime-type though.
这些回答对我都不起作用。我确实注意到了应用程序/json;utf - 8字符集= mime类型。
#4
5
I recommend this approach
Create CompressAttribute
class, and set target action.
我推荐这一方法创建CompressAttribute类,并设置目标操作。