I am having the file download failure where IE does not download a PDF over HTTPS as described here.

The solution seams simple enough, set the proper caching controls. The problem I am having is that no matter what I set the cache control headers to they show with the same values.

Here is the code

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

Here is the raw header from 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

No matter how I change the caching the result is always Cache-Control: no-cache, no-store and Pragma: no-cache.

What could be resetting the cache headers?

有帮助吗?

解决方案 2

I figured out I was changing the cache headers. The GetPDF method that creates the document class uses an HTML to PDF converter, and that HTML page was resetting the cache controls.

The OP code works correctly if you don’t subsequently change cache settings.

其他提示

With IIS 7.5+ use the URL Rewrite extention to add an outbound rule to strip off the "no-store" value in the Cache-Control header, and to strip the Pragma header. This rule set would do the trick:

<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>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top