配置IIS 7.5发送JSON响应gzip压缩,NO_MATCHING_CONTENT_TYPE [英] Configuring IIS 7.5 to send JSON responses gzipped, NO_MATCHING_CONTENT_TYPE

查看:1014
本文介绍了配置IIS 7.5发送JSON响应gzip压缩,NO_MATCHING_CONTENT_TYPE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图让我的应用程序使用动态COM pression和gzip发送其JSON响应。不幸的是,这是行不通的。在服务器上的所有静态COM pression工作正常,但不是动态的。

So I'm trying to get my app to send its JSON responses using dynamic compression and gzip. Unfortunately this isn't working. All the static compression on the server is working fine, but not dynamic.

我已经设置此加入:

<add mimeType="application/json" enabled="true" />
<add mimeType="application/json; charset=utf-8" enabled="true" />

&LT; dynamicTypes&GT; 部分&LT; httpCom pression&GT; 中的applicationHost.config文件。我使用的是查尔斯检查HTTP请求,我可以确认我送与的请求,接受编码:gzip,紧缩报头组。我已经试过既接受:* / * 接受:应用/ JSON 。当它不工作我启用了失败请求跟踪记录,以找出错误$ C $下 DYNAMIC_COM preSSION_NOT_SUCCESS ,这是 NO_MATCHING_CONTENT_TYPE

To the <dynamicTypes> section of <httpCompression> in the applicationHost.config file. I'm using Charles to inspect HTTP requests and I can verify that I'm sending the requests with the Accept-Encoding: gzip, deflate header set. I've tried with both Accept: */* and Accept: application/json. When it wasn't working I enabled 'Failed Request' trace logging to find the error code for DYNAMIC_COMPRESSION_NOT_SUCCESS, which was NO_MATCHING_CONTENT_TYPE.

我一直在尝试在论坛和谷歌的研究,但我可以看到的是人们说使用MIMETYPE使用指定的字符集解决了这个问题对他们来说,但在我的情况下,它仍然没有工作,我可以确认响应回来了头说内容类型:应用程序/ JSON;字符集= UTF-8

I've been trying to research on forums and Google, but all I can see is people saying that using the mimeType with the charset specified fixes the problem for them, but in my case it's still not working and I can verify that the response comes back with a header saying Content-Type: application/json; charset=utf-8

这是服务于JSON响应的端点被注解为标准.NET Web服务的ASMX [ScriptService()] 在类和 [ScriptMethod(UseHttpGet = TRUE,ResponseFormat = ResponseFormat.Json)] 的方法。他们返回JSON很好,但我不能让动态融为一体pression为我工作的生命。

The endpoints that serve the JSON responses are standard .NET ASMX WebServices annotated with [ScriptService()] at the class and [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] at the method. They return JSON fine, but I can't get the dynamic compression to work for the life of me.

由于这些是常规的网络方法以及我还补充道:

Since these are regular web methods as well I also added:

<add mimeType="text/xml" enabled="true" />
<add mimeType="text/xml; charset=utf-8" enabled="true" />

要尝试gzip压缩的XML响应。什么是令人沮丧的是,这个COM pression而来自同样的方法发送JSON不工作。在这一点上,我kindof处于亏损状态。

To attempt to gzip the XML responses. What's frustrating is that this compression works while sending JSON from the same method doesn't. At this point I'm kindof at a loss.

推荐答案

您想确保在 * / * MIME类型添加类型之后。另外,还要确保您已使用服务器管理器(或OptionalFeatures.exe)安装动态的COM pression模块

You want to make sure that the */* mime type is after the types you add. Also make sure that you have installed Dynamic Compression Module using Server Manager (or OptionalFeatures.exe)

这是我使用,以确保一个良好的COM pression完成的命令行。 (但要确保你确实已经安装了动态和静态的COM pression模块):

This is the command lines I use to make sure a good compression is done. (but make sure you actually have installed Dynamic and Static Compression modules):

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/serverRuntime /frequentHitThreshold:"1"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/urlCompression /doDynamicCompression:"True"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='application/json']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='application/json; charset=utf-8']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='application/javascript']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/javascript',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='application/x-javascript']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/x-javascript',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='application/x-javascript; charset=utf-8']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/x-javascript; charset=utf-8',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"dynamicTypes.[mimeType='*/*']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='*/*',enabled='False']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"staticTypes.[mimeType='application/javascript']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/javascript',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"staticTypes.[mimeType='application/x-javascript']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/x-javascript',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"staticTypes.[mimeType='application/x-javascript; charset=utf-8']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='application/x-javascript; charset=utf-8',enabled='True']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /-"staticTypes.[mimeType='*/*']"
call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /+"staticTypes.[mimeType='*/*',enabled='False']"

call %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpCompression /noCompressionForHttp10:"False" /noCompressionForProxies:"False" /minFileSizeForComp:"2700"

运行此您%WINDIR后%\ SYSTEM32 \ INETSRV \设置\对ApplicationHost.config应该是这个样子(注意, / 的是在底部):

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" minFileSizeForComp="2700" noCompressionForHttp10="false" noCompressionForProxies="false">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
    <dynamicTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/json" enabled="true" />
        <add mimeType="application/json; charset=utf-8" enabled="true" />
        <add mimeType="application/javascript" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/x-javascript; charset=utf-8" enabled="true" />
        <add mimeType="*/*" enabled="false" />
    </dynamicTypes>
    <staticTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/atom+xml" enabled="true" />
        <add mimeType="application/xaml+xml" enabled="true" />
        <add mimeType="application/javascript" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/x-javascript; charset=utf-8" enabled="true" />
        <add mimeType="*/*" enabled="false" />
    </staticTypes>
</httpCompression>

这篇关于配置IIS 7.5发送JSON响应gzip压缩,NO_MATCHING_CONTENT_TYPE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆