我有一个使用标准层在azure网站上运行的ASP.NET应用程序.我一直试图让gzip压缩工作.我修改了我的web.config文件,并在system.webServer下添加了以下内容
<urlCompression doStaticCompression="true" doDynamicCompression="true"/> <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"> <dynamicTypes> <add mimeType="text/*" enabled="true"/> <add mimeType="message/*" enabled="true"/> <add mimeType="application/javascript" 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/javascript" enabled="true"/> <add mimeType="application/x-javascript" enabled="true"/> <add mimeType="*/*" enabled="false"/> </staticTypes> </httpCompression>
这在使用IIS express本地运行时有效,但在部署到azure时不起作用.响应包含以下标头.
Accept-Ranges:bytes Content-Length:5381 Content-Type:text/css Date:Fri,04 Sep 2015 20:44:01 GMT ETag:"56386b2e88dad01:0" Last-Modified:Wed,19 Aug 2015 14:06:02 GMT Server:Microsoft-IIS/8.0 X-Powered-By:ASP.NET
解决方法
你错过了< scheme>元件
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
更多信息:
https://www.iis.net/configreference/system.webserver/httpcompression/scheme
<urlCompression doStaticCompression="true" doDynamicCompression="true"/> <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="message/*" enabled="true"/> <add mimeType="application/javascript" 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/javascript" enabled="true"/> <add mimeType="application/x-javascript" enabled="true"/> <add mimeType="*/*" enabled="false"/> </staticTypes> </httpCompression>