IIS 7.5 not compressing JSON when set in application web.config

旧街凉风 提交于 2019-12-21 17:25:23

问题


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:


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.



来源:https://stackoverflow.com/questions/10795165/iis-7-5-not-compressing-json-when-set-in-application-web-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!