【问题标题】:IIS HttpCompression settings to compress only json responses (ajax)IIS Http Compression 设置仅压缩 json 响应 (ajax)
【发布时间】:2013-08-31 14:22:15
【问题描述】:

我一直在玩“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>

如您所见,我添加了 &lt;add mimeType="application/json" enabled="true" /&gt; 行。这会确保只压缩使用 jquery 的动态 Ajax 调用吗?我正在使用以下方法调用我的 ASP.NET 页面方法:

$.ajax({
    type: "POST",
    url: 'someur.aspx/someMethod',
    contentType: "application/json; charset=utf-8",
    .....

我说的对吗?

【问题讨论】:

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


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 2018-09-17
      • 1970-01-01
      • 2012-02-12
      • 1970-01-01
      • 2011-01-29
      • 2014-09-09
      • 1970-01-01
      • 2012-07-21
      相关资源
      最近更新 更多