2013-10-19 87 views
1

我确实在我的IIS 7.5 Web服务器上正确设置了gzip,它在大多数情况下都能正常工作。如何从ASP.NET MVC中的JsonResult操作返回gzip json?

但我可以看到响应头显示我对JsonResult方法所做的任何请求都没有被压缩。我需要更改什么以便JsonResult通过Content-Encoding返回数据:gzip?

这是标题的截图调用JsonResult方法时:相比于调用的东西,返回HTML,如的RenderPartial()时,头部的截图

enter image description here

enter image description here

编辑:这些是我从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> 
+0

如果更改<添加mime类型= “*/*”>已启用=真,并在JSON得到压缩?这篇文章提到调试该场景(http://blogs.msdn.com/b/asiatech/archive/2013/02/19/unable-to-compress-json-result-in-iis-7-x.aspx) – Jedidja

+0

你的applicationHost.config和你的web.config中的urlCompression设置是什么? – brucwhi

回答

1

请确保您的IIS applicationHost.config文件位于%WinDir%\ System32 \ inetsrv \ config \ 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> 
+0

不幸的是,这些设置已经设置为TRUE。我用我的压缩设置更新了这个问题。 –

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

+0

对不起,我试着设置'frequentHitThreshold = 1',但这仍然没有帮助。 –

相关问题