1

我确实在我的 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>
4

2 回答 2

1

请确保位于%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-04T07:59:31.813 回答
0

您的配置看起来正确。可能是您尚未达到 IIS 开始压缩所有内容的阈值。

试试这个:在 IIS 管理器中,转到配置编辑器,然后找到 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

于 2014-08-10T14:54:32.983 回答