Why is IIS 7 is ignoring certain (but not all) MIME types for compression? Giving error: DYNAMIC_COMPRESSION_NOT_SUCCESS - Reason 12

So, I'm a bit of an IIS7 n00b but I've used most of the old IIS systems going back to 3. I'm trying to turn on dynamic compression and it's working, mostly. It doesn't work for my ADO.Net Data Service (Astoria) requests, batched or not.

I found the failed request (FREB) tracing which was really helpful. And what I see on unbatched requests is Reason Code 12, NO_MATCHING_CONTENT_TYPE. OK, so I don't have the matching MIME type specified, that's easy.

Except this is what I have in my web.config (which I think is correct, but maybe not).

<httpCompression dynamicCompressionDisableCpuUsage="100"
                 dynamicCompressionEnableCpuUsage="100"
                 noCompressionForHttp10="false"
                 noCompressionForProxies="false"
                 noCompressionForRange="false"
                 sendCacheHeaders="true"
                 staticCompressionDisableCpuUsage="100"
                 staticCompressionEnableCpuUsage="100">
    <dynamicTypes>
        <clear/>
        <add mimeType="*/*"
             enabled="true" />
    </dynamicTypes>
    <staticTypes>
        <clear/>
        <add mimeType="*/*"
             enabled="true" />
    </staticTypes>
</httpCompression>
<urlCompression doDynamicCompression="true"
                doStaticCompression="true"
                dynamicCompressionBeforeCache="false" />

Now I think that this means it should compress any request that includes the Accept:Gzip header. I'd love to know what others might think here.

My fiddler trace:

GET /SecurityDataService.svc/GetCurrentAccount HTTP/1.1
Accept-Charset: UTF-8
Accept-Language: en-us
dataserviceversion: 1.0;Silverlight
Accept: application/atom+xml,application/xml
maxdataserviceversion: 1.0;Silverlight
Referer: http://sdev03/apptestpage.aspx
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.21022; .NET CLR 3.5.30729; InfoPath.2; .NET CLR 3.0.30729; OfficeLiveConnector.1.4; OfficeLivePatch.1.3)
Host: sdev03
Connection: Keep-Alive
Cookie: .ASPXAUTH=<snip>


HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Type: application/atom+xml;charset=utf-8
Server: Microsoft-IIS/7.0
DataServiceVersion: 1.0;
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Mon, 22 Mar 2010 22:29:06 GMT
Content-Length: 2726

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
*** <snip> removed ***

OK, turns out you can't configure this in the web.config, only the appHost.config. I supposed the docs did say appHost.config but I had assumed it was a specification of a general concept, not the only allowable configuration location.


Peter, thanks for the hint -- we also found that setting

<add mimeType="application/atom+xml; charset=utf-8" enabled="true" />

in the <httpCompression> section of applicationHost.config fixed this.

We also had to specify the encoding due to a bug in compression code:

There is a bug in the compression code that it does not parse the charset in the response header correctly, so you will have to configure "application/xml; charset=utf-8" in the dynamic compression settings to have it work.

Here's the relevant section in full

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" dynamicCompressionLevel="4" />
    <scheme name="deflate" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" dynamicCompressionLevel="4" />
    <dynamicTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/atom+xml; charset=utf-8" 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="*/*" enabled="false" />
    </staticTypes>
</httpCompression>

From a fresh install, my applicationHost.config (in %windir%\system32\inetsrv\config) had the following setting:

<section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />

... as well as a default set of MIME types to compress that, unfortunately, doesn't include JSON and other data types that would be good compression candidates.

Switching that to:

<section name="httpCompression" overrideModeDefault="Allow" />

enables configuration of the httpCompression tag under the system.webServer tag in my web.config.

I confirmed this by setting the httpCompression section of the applicationHost.config to:

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
    <dynamicTypes>
        <add mimeType="*/*" enabled="false" />
    </dynamicTypes>
    <staticTypes>
        <add mimeType="*/*" enabled="false" />
    </staticTypes>
</httpCompression>

... and now I can set all the MIME types I actually want to compress in the web.config.