我确实在我的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>https://stackoverflow.com/questions/19464025
复制相似问题