下面的配置工作具體充分的權利爲了我。只需將applicationHost.config中的httpCompression部分替換爲下面給出的部分,然後重新啓動IIS即可。而已!!!
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"
staticCompressionDisableCpuUsage="95" staticCompressionEnableCpuUsage="60"
dynamicCompressionDisableCpuUsage="95" dynamicCompressionEnableCpuUsage="50">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
<add mimeType="application/json" enabled="true" />
<add mimeType="application/json; charset=utf-8" enabled="true" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" 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="application/json" enabled="true" />
<add mimeType="application/json; charset=utf-8" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
配置在此之後,我在響應指示數據被使用gzip壓縮來壓縮
Cache-Control → no-cache
Content-Encoding → gzip
Content-Length → 4202
Content-Type → application/json; charset=utf-8
Date → Wed, 22 Jul 2015 07:40:17 GMT
Expires → -1
Pragma → no-cache
Vary → Accept-Encoding
X-Powered-By → ASP.NET
以上配置是整個IIS得到了以下標題。如果你想在一個網站上配置此然後用
<section name="httpCompression" overrideModeDefault="Allow" />
中的applicationHost.config和代替的applicationHost.config更換httpCompression部分取代
<section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
,下system.webServer標籤添加它在您的網站的web.config中
另外,請確保您爲數據指定了正確的MIME類型。在我的情況下,它是在JSON,所以我用下面的配置
<add mimeType="application/json" enabled="true" />
<add mimeType="application/json; charset=utf-8" enabled="true" />
感謝偉大的文章。爲我工作 – abzarak 2013-07-25 13:39:15