如何在运行 runAllManagedModulesForAllRequests 的 IIS 7 中禁用 flv 文件的 gzip 压缩?

5
我有一个运行在IIS 7上的ASP.NET 3.5网站,希望对静态内容(如css文件、javascript文件等)和动态内容(.net页面)进行gzip压缩。但是问题在于,我需要确保flv文件(flash视频文件)不被gzip压缩,因为这会导致我使用的flash视频播放器Flowplayer出现问题。
我已经在web.config中添加了以下行以启用压缩,但这样会使我的flv文件也被gzip压缩:
<urlCompression doStaticCompression="true" doDynamicCompression="true" />

我尝试将以下内容添加到我的web.config文件中,但没有任何变化:
<httpCompression>
    <staticTypes>
        <remove mimeType="video/x-flv"/>
    </staticTypes>
    <dynamicTypes>
        <remove mimeType="video/x-flv"/>
    </dynamicTypes>
</httpCompression>

我必须关闭doDynamicCompression以防止flv文件被gzip压缩。我认为它将flv文件视为动态内容,因为我在web.config中运行了runAllManagedModulesForAllRequests="true"(我需要使用路由进行某些操作)。
总之,我如何禁用flv文件的gzip压缩?

这是我认为你想要的内容:<add mimeType="video/x-flv" enabled="false" />请注意,我认为这只能在IIS7的ApplicationHost.config级别上完成。 - LMA1980
1个回答

2

我认为最好的做法是手动管理gzip压缩的内容。有时候,被gzip压缩的内容实际上会增加大小,比如swf文件,这就是我刚遇到的情况。以前我的application.config中有这个块,但是在我删除了shockwave mime类型后,swf文件停止了压缩。

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
        <dynamicTypes>
                <clear />
                <add mimeType="text/*" enabled="true" />
                <add mimeType="message/*" enabled="true" />
                <add mimeType="application/x-javascript" enabled="true" />
                <add mimeType="application/x-amf" enabled="true" />
                <add mimeType="application/json" enabled="true" />
                <add mimeType="application/json; charset=utf-8" enabled="true" />
                <add mimeType="application/x-shockwave-flash" enabled="true" /> <!-- notice the swf mime type -->
                <add mimeType="*/*" enabled="false" />
        </dynamicTypes>
        <staticTypes>
                <clear />
                <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/x-shockwave-flash" enabled="true" /> <!-- notice the swf mime type -->
                <add mimeType="*/*" enabled="false" />
        </staticTypes>
    </httpCompression>

这是我应用程序配置中的内容,位于windows\system32\intersrv\config\application.config,但我相信您可以在system.webserver下的web.config中为每个网站进行此操作。
对我来说,所需的只是删除Shockwave MIME类型,它就不会被压缩,但所有其他有效的MIME类型都会被压缩。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接