Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpCompression element in web.config not read in IIS7.5

I'm trying to override the httpCompression element within Web.config for a site on an IIS 7.5 running Windows 7, but it does not seem to be read at all.

To check, I've introduced typeos within the element, but I can't even get a configuration error.

Here is an example of the httpCompression element from Web.config

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
  <SCHEMEx name="deflate" dll="%Windir%\system32\inetsrv\gzip.dll" />
  <dynamicTypes>
    <add mimeType="text/*" enabled="false" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </dynamicTypes>
  <staticTUPES>
  </staticTUPES>
</httpCompression>

When I introduce similar errors in other element (like ie modules) I get a configuration error, so I know the config file is read.

I've unlocked the section in ApplicationHost.config:

appcmd unlock config /section:system.webserver/httpcompression

But that did not work, so I changed ApplicationHost.config manually so it now reads:

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

What I'm really trying to accomplish is to set "deflate" as the only compression scheme for one of my sites.

like image 824
madsny Avatar asked Nov 09 '11 18:11

madsny


1 Answers

For this to work, after unlocking the application.config file you have to set the specific configuration via command line as well..

1) Unlock the httpCompression part of the application.config:

C:\Windows\System32\inetsrv\appcmd.exe unlock config /section:system.webServer/httpCompression

2) Lets suppose you want to handle dynamic JSON requests (e.g. mimetype = application/json), you should use this command:

C:\Windows\System32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json',enabled='True']" /commit:apphost

3) If JSON requests is your case, you might also want to handle the charset=utf-8 variation, which for some reason is what IIS gives you back in most cases:

C:\Windows\System32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='True']" /commit:apphost
like image 82
Tuco Avatar answered Oct 03 '22 22:10

Tuco