5

I've been working on enabling JSON compression from one of our MVC3 sites. From various articles I've read it seems as though I should be able to set the application/json; charset=utf-8 MIME type in the applications web.config file. But doing so does not enable compression. But when added to the applicationhost.config file, it works. Am I missing something here?

My application web.config has the following added to it:

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
    <dynamicTypes>
        <add mimeType="application/javascript; charset=utf-8" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/json" enabled="true" />
        <add mimeType="application/json; charset=utf-8" enabled="true" />
    </dynamicTypes>
    <staticTypes>
        <add mimeType="application/javascript; charset=utf-8" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/json" enabled="true" />
        <add mimeType="application/json; charset=utf-8" enabled="true" />
    </staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />

The server is running Windows Server 2008 R2 with IIS7.5. I've also installed & enabled Dynamic Compression for the site in question.

Any help would be greatly appreciated, as I do not wish to enable JSON compression for the entire server.

1
  • Please have a look at this post: stackoverflow.com/a/7634875/1131855 I was not able to edit applicationHost.config via Notepad++. This link suggested a console command which worked for me Commented Nov 18, 2014 at 17:01

1 Answer 1

11

HttpCompression section is defined AppHostOnly in ApplicationHost.config which prevents you from setting its properties in web.config.

The compression module reads only the server level properties from 'ApplicationHost.config' so even if you unlock the section (with appcmd or overrideModeDefault="Allow"), settings on lower level will be ignored.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for that, it cleared up the confusion. It turns out that even if you add a <location> element to the ApplicationHost.config for a site to try and allow HttpCompression at the site level, it remains locked because of the AppHostOnly attribute. The only way is to add the application/json MIME type to the "global" <httpCompression> section in ApplicationHost.config & thus turn it on for all sites on the server.
@tpeczek The compression module reads only the server level properties from 'ApplicationHost.config' Do you have a source for that? I can't find anything official from Microsoft, even though it absolutely looks to be the case, especially with IIS8+

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.