我如何COM preSS从ASP.NET MVC与IIS 7.5 JSON结果 [英] How do I compress a Json result from ASP.NET MVC with IIS 7.5

查看:125
本文介绍了我如何COM preSS从ASP.NET MVC与IIS 7.5 JSON结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有困难,使得IIS 7正确COM preSS从ASP.NET MVC一个JSON结果。我在IIS中启用静态和动态融为一体pression。我可以使用Fiddler验证正常的text / html和类似的记录是COM pressed。查看请求,接受编码,gzip头是present。响应有MIME类型应用程序/ JSON,而不是COM pressed。

我已经确定,这个问题似乎涉及到媒体类型。当我包括 mime类型=* / *,我可以看到,响应正确gzip压缩。我怎样才能获得IIS以COM preSS不使用通配符mime类型?我认为,这个问题牵扯到与ASP.NET MVC生成的内容类型头的方式。

CPU使用率远低于动态限制门槛。当我检查IIS中的跟踪日志,我可以看到它未能COM preSS由于没有找到匹配的MIME类型。

 < httpCom pression目录=的%SystemDrive%\\的Inetpub \\ TEMP \\ IIS临时的COM pressed文件noCom pressionForProxies =false的>
    <方案名称=gzip的DLL =%WINDIR%\\ SYSTEM32 \\ INETSRV \\ gzip.dll/>
    < dynamicTypes>
        <添加mime类型=文/ *启用=真/>
        <添加mime类型=消息/ *启用=真/>
        <添加mime类型=应用程序/ x-JavaScript的启用=真/>
        <添加mime类型=应用/ JSON启用=真/>
    < / dynamicTypes>
    < staticTypes>
        <添加mime类型=文/ *启用=真/>
        <添加mime类型=消息/ *启用=真/>
        <添加mime类型=应用程序/ x-JavaScript的启用=真/>
        <添加mime类型=应用程序/原子+ XML启用=真/>
        <添加mime类型=应用/ XAML + XML启用=真/>
        <添加mime类型=应用/ JSON启用=真/>
    < / staticTypes>
< / httpCom pression>


解决方案

请确保您的%WINDIR%\\ SYSTEM32 \\ INETSRV \\设置\\的applicationHost.config 包含这些:

 < system.webServer>
    < urlCom pression doDynamicCom pression =真/>
    < httpCom pression>
      < dynamicTypes>
        <添加mime类型=应用/ JSON启用=真/>
        <添加mime类型=应用/ JSON的;字符集= UTF-8启用=真/>
      < / dynamicTypes>
    < / httpCom pression>
< /system.webServer>

从@AtanasKorchev的链接

由于@simon_weaver在评论中说,你可能会被编辑用在64位Windows 32位编辑了错误的文件,使用的notepad.exe以确保该文件确实修改。

I'm having difficulty making IIS 7 correctly compress a Json result from ASP.NET MVC. I've enabled static and dynamic compression in IIS. I can verify with Fiddler that normal text/html and similar records are compressed. Viewing the request, the accept-encoding gzip header is present. The response has the mimetype "application/json", but is not compressed.

I've identified that the issue appears to relate to the MimeType. When I include mimeType="*/*", I can see that the response is correctly gzipped. How can I get IIS to compress WITHOUT using a wildcard mimeType? I assume that this issue has something to do with the way that ASP.NET MVC generates content type headers.

The CPU usage is well below the dynamic throttling threshold. When I examine the trace logs from IIS, I can see that it fails to compress due to not finding a matching mime type.

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files" 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/x-javascript" enabled="true" />
        <add mimeType="application/json" enabled="true" />
    </dynamicTypes>
    <staticTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/atom+xml" enabled="true" />
        <add mimeType="application/xaml+xml" enabled="true" />
        <add mimeType="application/json" enabled="true" />
    </staticTypes>
</httpCompression>

解决方案

Make sure your %WinDir%\System32\inetsrv\config\applicationHost.config contains these:

<system.webServer>
    <urlCompression doDynamicCompression="true" />
    <httpCompression>
      <dynamicTypes>
        <add mimeType="application/json" enabled="true" />
        <add mimeType="application/json; charset=utf-8" enabled="true" />       
      </dynamicTypes>
    </httpCompression>
</system.webServer>

From the link of @AtanasKorchev.

As @simon_weaver said in the comments, you might be editing the wrong file with a 32 bit editor on a 64 bit Windows, use notepad.exe to make sure this file is indeed modified.

这篇关于我如何COM preSS从ASP.NET MVC与IIS 7.5 JSON结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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