【发布时间】:2013-10-19 08:23:48
【问题描述】:
我确实在我的 IIS 7.5 Web 服务器上正确设置了 gzip,它在大多数情况下都能正常工作。
但是我可以看到响应标头显示我对 JsonResult 方法发出的任何请求都没有被压缩。我需要更改什么以便 JsonResult 返回带有 Content-Encoding: gzip 的数据?
这是调用 JsonResult 方法时的头部截图:
与调用返回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>
【问题讨论】:
-
如果您将
更改为 enabled=true,JSON 会被压缩吗?这篇文章提到了调试该场景 (blogs.msdn.com/b/asiatech/archive/2013/02/19/…) -
您的 applicationHost.config 和 web.config 中的 urlCompression 设置是什么?
标签: c# asp.net-mvc json iis-7 gzip