Gar*_*aul 56 asp.net asp.net-mvc iis-7 json http-compression
我很难让IIS 7正确压缩来自ASP.NET MVC的Json结果.我在IIS中启用了静态和动态压缩.我可以向Fiddler验证正常的text/html和类似的记录是否被压缩.查看请求时,会出现accept-encoding gzip标头.响应具有mimetype"application/json",但未压缩.
我发现问题似乎与MimeType有关.当我包含时mimeType="*/*",我可以看到响应是正确的gzip压缩.如何在不使用通配符mimeType的情况下使用IIS进行压缩?我假设这个问题与ASP.NET MVC生成内容类型头的方式有关.
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>
Run Code Online (Sandbox Code Playgroud)
dee*_*hao 59
确保您的%WinDir%\ System32\inetsrv\config\applicationHost.config包含以下内容:
<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>
Run Code Online (Sandbox Code Playgroud)
来自@AtanasKorchev 的链接.
正如@simon_weaver在评论中所说,您可能在64位Windows上使用32位编辑器编辑错误的文件,使用notepad.exe确保此文件确实已修改.
| 归档时间: |
|
| 查看次数: |
33826 次 |
| 最近记录: |