IIS HttpCompression设置仅压缩json响应(ajax)

时间:2013-08-31 14:22:15

标签: asp.net ajax json iis http-compression

我一直在使用“C:\ Windows \ System32 \ inetsrv \ config”目录中的“applicationHost.config”文件,到目前为止一直很好,我只是想确定一些事情:

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

如您所见,我添加了行<add mimeType="application/json" enabled="true" />。这是否会确保只使用jquery进行动态Ajax调用?我使用:

调用我的ASP.NET页面方法
$.ajax({
    type: "POST",
    url: 'someur.aspx/someMethod',
    contentType: "application/json; charset=utf-8",
    .....

我说错了吗?

1 个答案:

答案 0 :(得分:1)

您需要添加2种内容类型才能为JSON启用动态压缩:

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

                    <!-- all other MIME type come here -->

                <add mimeType="*/*" enabled="false" />
            </dynamicTypes>
        </httpCompression>