I have an .aspx page that returns a PDF. Below is the code on Page_PreRender.
Protected Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
Dim pdfStream As MemoryStream
pdfStream = CType(Cache("PdfViewerContent"), MemoryStream)
Response.BufferOutput = True
Response.ClearContent()
Response.ClearHeaders()
Response.AddHeader("Cache-control", "no-store")
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Length", pdfStream.Length.ToString())
Response.AddHeader("Content-Disposition", "attachment=PDFFile.pdf")
Response.BinaryWrite(pdfStream.ToArray())
Response.Flush()
HttpContext.Current.ApplicationInstance.CompleteRequest()
End Sub
This page is launched from a window.open javascript call.
This works fine on Windows 7 with IE9, Chrome, and Firefox. However, on Windows XP running IE7, the browser just flickers and no window is opened. (Popup Blocker is disabled) With Chrome I get an error in developer console "Resource Interpreted as Document but transferred with MIME type application/pdf" and the page is downloaded as a file.
I believe it should be
Response.AddHeader("Content-Disposition", "attachment; filename=PDFFile.pdf")
Also, I would call Response.End()
just after Response.Flush()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.