我有文件下载失败的地方IE浏览器没有按照here所述通过HTTPS下载PDF。
解决方案接缝很简单,设置正确的缓存控件。我遇到的问题是,无论我将缓存控制头设置为什么,它们都显示相同的值。
这是代码
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。
什么可以重置缓存标头?
答案 0 :(得分:0)
使用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>
答案 1 :(得分:0)
我发现我正在更改缓存标头。创建文档类的GetPDF方法使用HTML到PDF转换器,该HTML页面正在重置缓存控件。
如果您不随后更改缓存设置,OP代码将正常工作。