我在尝试让ASP.NET MVC返回的Json结果在IIS 7上正确压缩时遇到了困难。我已经在IIS中启用了静态和动态压缩。我可以通过Fiddler验证普通的文本/HTML和类似的记录已被压缩。查看请求时,accept-encoding gzip头已存在。响应具有Mimetype“application/json”,但未被压缩。
我已确定问题似乎与MimeType有关。当我包括mimeType="*/*"
时,我可以看到响应已被正确地压缩。如何在不使用通配符MimeType的情况下让IIS进行压缩?我认为这个问题与ASP.NET MVC生成内容类型标头的方式有关。
CPU使用率远低于动态调节阈值。当我检查来自IIS的跟踪日志时,我发现它无法压缩因为未找到匹配的MimeType。
<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>