【问题标题】:What could be changing cache control settings for a file download?什么可能会更改文件下载的缓存控制设置?
【发布时间】:2014-04-25 07:05:11
【问题描述】:

我遇到文件下载失败,即 IE 无法通过 HTTPS 下载 PDF,如 here 所述。

解决方案非常简单,只需设置适当的缓存控件即可。我遇到的问题是,无论我将缓存控制标头设置为什么,它们都以相同的值显示。

这里是代码

context.Response.ClearContent()
context.Response.ClearHeaders()
context.Response.AppendHeader("Content-Disposition", String.Format("attachment;filename=RiskSummaryForm {0}.pdf", intSubno))
context.Response.ContentType = "application/pdf"
context.Response.AppendHeader("Cache-Control", "no-store, no-cache, must-revalidate")
context.Response.AppendHeader("X-Footest", "no-store, no-cache, must-revalidate")
'context.Response.AppendHeader("Pragma", "token")
'context.Response.Cache.SetCacheability(HttpCacheability.Private)
Dim Doc As Document = GACIS.PRB.Doc.RiskSummaryForm.GetPDF(context, DocumentDataFormat.Binary)
context.Response.OutputStream.Write(Doc.DataBinary, 0, Doc.DataBinary.Length)
HttpContext.Current.ApplicationInstance.CompleteRequest()

这是 Fiddler2 的原始标头:

HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Type: text/html
Expires: -1
Server: Microsoft-IIS/7.5
Content-Disposition: attachment;filename=RiskSummaryForm 300185.pdf
X-Footest: no-store, no-cache, must-revalidate
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sat, 04 Jan 2014 00:19:01 GMT
Content-Length: 78193

无论我如何更改缓存,结果始终是 Cache-Control: no-cache, no-store 和 Pragma: no-cache。

什么可能会重置缓存标头?

【问题讨论】:

    标签: internet-explorer caching https file-transfer


    【解决方案1】:

    对于 IIS 7.5+,使用 URL Rewrite extention 添加出站规则以去除 Cache-Control 标头中的“no-store”值,并去除 Pragma 标头。这个规则集可以解决问题:

    <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>
    

    【讨论】:

      【解决方案2】:

      我发现我正在更改缓存标头。创建文档类的 GetPDF 方法使用 HTML 到 PDF 转换器,并且该 HTML 页面正在重置缓存控件。

      如果您随后不更改缓存设置,则 OP 代码可以正常工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-18
        • 2011-10-01
        • 1970-01-01
        • 2020-05-01
        • 1970-01-01
        • 2017-07-16
        • 1970-01-01
        • 2018-09-10
        相关资源
        最近更新 更多