我确实在我的IIS7.5Web服务器上正确设置了gzip,并且它在大多数情况下都可以工作。
但是我可以看到响应头显示我对JsonResult方法的任何请求都不是gzipped格式的。我需要做什么更改才能让JsonResult返回带有Content-Encoding: gzip的数据?
这是调用JsonResult方法时的headers截图:

与调用返回html的东西时的标题截图相比,例如RenderPartial():

编辑:以下是我在applicationHost.config中的压缩设置:
<httpCompression
directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="application/json" enabled="true" />
<add mimeType="application/json; charset=utf-8" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/json" enabled="true" />
<add mimeType="application/json; charset=utf-8" 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="*/*" enabled="false" />
</staticTypes>
</httpCompression>发布于 2014-08-04 15:59:32
请确保位于%WinDir%\System32\inetsrv\config\applicationHost.config的IIS 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>发布于 2014-08-10 22:54:33
您的配置看起来是正确的。这可能是因为您尚未达到IIS开始压缩所有内容的阈值。
尝试这样做:在IIS管理器中,转到Configuration Editor,并找到system.WebServer/serverRuntime。查看frequentHitThreshold和frequentHitTimePeriod设置,并向下拉出这些设置,以确保您在测试时达到阈值。
这里有更多的阅读:http://blogs.msdn.com/b/asiatech/archive/2013/02/19/unable-to-compress-json-result-in-iis-7-x.aspx
https://stackoverflow.com/questions/19464025
复制相似问题