无法使用 PreSendRequestHeaders() 覆盖 IIS 中的 http 缓存标头

Ant*_*mas 5 asp.net iis-6 http-headers

历史:
出于安全考虑,我们的组织希望通过向 IIS 添加 HTTP 标头来禁用缓存。

过期:-1
Pragma:无缓存
缓存控制:无缓存、无存储

添加这些标头会导致 MIME“ application/vnd.ms-excel ”响应类型在IE6中对SSL进行故障转移。Microsoft 承认这是一个错误 ( http://support.microsoft.com/kb/323308 ),并且他们的解决方案也有效。然而,该解决方案必须作为补丁在整个组织中推广,并且面临更高管理层的阻力。

问题:
同时,我们尝试通过使用PreSendRequestHeaders()函数上的HTTPModules覆盖 IIS 设置 MIME 类型“application/vnd.ms-excel”页面的 HTTP 标头来找到替代方案

//this is just a sample code
public void Init(HttpApplication context)
        {
            context.PreSendRequestHeaders += new EventHandler(context_PreSendRequestHeaders);

        }
protected void context_PreSendRequestHeaders(object sender, EventArgs e) 
        {
            HttpApplication application = (HttpApplication)sender;
            if(application.Response.ContentType == "application/vnd.ms-excel; name=DataExport.xls")
            {
                application.Response.ClearHeaders();
                application.Response.ContentType = "application/vnd.ms-excel; name=DataExport.xls";
                application.Response.AddHeader("Content-Transfer", "Encoding: base64");
                application.Response.AddHeader("Content-Disposition", "attachment;filename=DataExport.xls");
                application.Response.AddHeader("cache-control","private");
            }
        }
Run Code Online (Sandbox Code Playgroud)

即使使用 ClearHeaders() 清除标头后,IIS 仍会在发送响应之前附加缓存标头。

问题:
在 PreSendRequestHeaders() 函数中使用 ClearHeaders() 的这种方法是否错误?他们是否有使用 ASP.NET 1.1 中可用的库来覆盖缓存标头(Expires、Pragma、cache-control)的替代方案?

其他:
我们使用的
浏览器:IE6 SP 3
服务器:IIS 6
平台:.NET 1.1

Geo*_*ath 2

在 IIS 7.5+ 中,使用URL 重写扩展并添加出站规则来去除 Cache-Control 标头和 Pragma 标头中的“no-store”值,这会变得更容易。这个规则集可以解决问题:

<outboundRules>
    <rule name="Always Remove Pragma Header">
        <match serverVariable="RESPONSE_Pragma" pattern="(.*)" />
        <action type="Rewrite" value="" />
    </rule>
    <rule name="Remove No-Store for Attachments">
        <conditions>
            <add input="{RESPONSE_Content-Disposition}" pattern="attachment" />
        </conditions>
        <match serverVariable="RESPONSE_Cache-Control" pattern="no-store" />
        <action type="Rewrite" value="max-age=0" />
    </rule>
</outboundRules>
Run Code Online (Sandbox Code Playgroud)