问题描述
我已经添加了web.config条目以基于此S/O答案启用gzip压缩启用IIS7 gzip .
I have added the web.config entry to enable gzip compression based on this S/O answer Enable IIS7 gzip.
然后我在加载ASPX页面时检查了Chrome开发者窗口,并在响应中看到了标头:
I then checked the Chrome Developer window while loading an ASPX page and saw the header in the response:
Cache-Control:private
Content-Encoding:gzip
Content-Length:3669
Content-Type:text/html; charset=utf-8
Date:Wed, 04 Mar 2015 00:46:05 GMT
Server:Microsoft-IIS/7.5
Vary:Accept-Encoding
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
这意味着它正在起作用",对吗?但是,在进行Web API调用时查找该标头时,该标头不存在:
So that means it's "working", correct? But when looking for that header when making a Web API call, it is not present:
Cache-Control:no-cache
Content-Length:551
Content-Type:application/json; charset=utf-8
Date:Wed, 04 Mar 2015 00:53:05 GMT
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/7.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
我尝试了各种不同的配置(从上面链接的S/O回答中建议的一种开始).最后,我无奈之下将其设置为此,我认为这将使其尝试压缩所有请求(除*/*以外的所有内容):
I have tried all kinds of different configurations (starting with the one recommended in the linked S/O answer above). Finally, in an act of desperation, I set it to this, which I thought would make it try to compress all requests (everything except */* commented out):
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
<dynamicTypes>
<add mimeType="*/*" enabled="true"/>
<!--<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="application/json" enabled="true"/>-->
<!--<add mimeType="*/*" enabled="false"/> -->
</dynamicTypes>
<staticTypes>
<add mimeType="*/*" enabled="true"/>
<!--<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="application/json" enabled="true"/>-->
<!-- add mimeType="*/*" enabled="false"/>-->
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>
什么可以阻止GZIP应用于我的Web API方法?
What can be preventing the GZIP from being applied to my Web API methods?
更新
此后,我都尝试了 NuGet Web API压缩程序包,然后在IIS Express 8.0(Visual Studio)和本地安装的IIS 7.5中编辑applicationHost.config.所有这些都产生了相同的结果:对其他MIME类型(例如text/*)的请求有效,但是application/json拒绝压缩.
I have since tried both the NuGet Web API Compression package, and editing the applicationHost.config in both IIS Express 8.0 (Visual Studio) and a locally-installed IIS 7.5. All have yielded the same results: requests for other mime types like text/* work, but application/json refuses to be gzipped.
推荐答案
WebAPI是否位于防火墙,Web代理,病毒防护套件的后面?如11-03 03:19