问题
I'm working on a ASP.Net website, and are currently optimizing it. I'm trying to enable dynamic content compression to it, but it won't work.
I get
Error 330 (net::ERR_CONTENT_DECODING_FAILED): Unknown error.
On my development environment it works well.
- I've built the project in release mode I've added the dynamic content compression module, enabled dynamic content compression and checked that this is what i receive.
I have an AWS EC2 server windows 2008 R2 with IIS installed.
- I've built the project in release mode, and publish it to a folder, which i deploy to the server.
- I've tried with the same web.config file as i have on the developer machine, but no luck there
Added this to web.config:
<httpCompression
directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"
dynamicCompressionDisableCpuUsage="90"
dynamicCompressionEnableCpuUsage="80"
maxDiskSpaceUsage="100" minFileSizeForComp="2700"
noCompressionForRange="true"
sendCacheHeaders="false"
staticCompressionDisableCpuUsage="100"
staticCompressionEnableCpuUsage="80"
>
<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/json" enabled="true" />
<add mimeType="application/xml" 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/json" enabled="true" />
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/rss+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="application/xml" enabled="true" />
<add mimeType="image/svg+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
<urlCompression doDynamicCompression="true" />
Anybody have an idea of what could be wrong?
Thanks in advance.
EDIT: Tried running the request through fiddler and got the response: "The content could not be decompressed.
The magic number in GZip header is not correct. Make sure you are passing in a GZip stream."
回答1:
We encountered this problem caused IIS Temporary Compressed Files which were corrupt/truncated due to the disk running out of space:
- Run
inetmgr
- Go to the machine, Compression feature
- Delete the contents of the Cache directory
回答2:
A colleague of mine had this exact same problem.
He was running his application with a non-standard application pool identity. For the sake of this solution I will call that identity SomeOtherApplicationPoolIdentity
.
The problem was that it was lacking permissions to a sub-folder in his cache directory (to see what cache directory IIS uses, go to the IIS Manager, click the top-level tree node, click on Compression; by default it is %SystemDrive%\inetpub\temp\IIS Temporary Compressed Files
):
Inside of %SystemDrive%\inetpub\temp\IIS Temporary Compressed Files
, he was missing permissions for a sub-folder named, SomeOtherApplicationPoolIdentity
, contextually named according to his application pool identity, so he just inherited permissions from the parent folder from that sub-folder and it worked, because the parent folder generally grants permissions to the IIS_IUSRS
, SYSTEM
, Administrators
, and local administrative user account.
回答3:
try to specify dynamicCompressionBeforeCache="false"
I was trying to use dynamicCompressionBeforeCache="true" because I thought it will cause my cached objects to be saved compressed - so that they can be served as smaller files, but got the same error...
<!--http://www.iis.net/configreference/system.webserver/urlcompression-->
<urlCompression doStaticCompression="true" doDynamicCompression="true" dynamicCompressionBeforeCache="false" />
<httpCompression
directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"
dynamicCompressionDisableCpuUsage="90"
dynamicCompressionEnableCpuUsage="80"
maxDiskSpaceUsage="100"
minFileSizeForComp="2700"
noCompressionForRange="true"
sendCacheHeaders="false"
staticCompressionDisableCpuUsage="100"
staticCompressionEnableCpuUsage="80">
<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/json" enabled="true" />
<add mimeType="application/xml" 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/json" enabled="true" />
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/rss+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="application/xml" enabled="true" />
<add mimeType="image/svg+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
http://www.iis.net/configreference/system.webserver/urlcompression
The dynamicCompressionBeforeCache attribute specifies whether IIS will dynamically compress content that has not been cached. When the dynamicCompressionBeforeCache attribute is true, IIS dynamically compresses the response the first time a request is made and queues the content for compression. Subsequent requests are served dynamically until the compressed response has been added to the cache directory. Once the compressed response is added to the cache directory, the cached response is sent to clients for subsequent requests. When dynamicCompressionBeforeCache is false, IIS returns the uncompressed response until the compressed response has been added to the cache directory.
Note: If the dynamicCompressionBeforeCache attribute is true when the output cache response has been flushed, dynamic compression will not be performed before the response is put into the output cache. However, if the doDynamicCompression attribute is true, dynamic compression will still occur after the output cache has been filled with the response.
回答4:
my idea is to check if the application pool user (if you have any specific) has full rights to directory "%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"
来源:https://stackoverflow.com/questions/15112104/how-to-fix-err-content-decoding-failed-when-dynamic-compressing