【问题标题】:ASPX page does not render PDF in IE7 and Chrome on Windows XPASPX 页面无法在 Windows XP 上的 IE7 和 Chrome 中呈现 PDF
【发布时间】:2012-07-13 19:14:04
【问题描述】:

我有一个返回 PDF 的 .aspx 页面。下面是 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

此页面是从 window.open javascript 调用启动的。

这在带有 IE9、Chrome 和 Firefox 的 Windows 7 上运行良好。但是,在运行 IE7 的 Windows XP 上,浏览器只是闪烁,没有打开任何窗口。 (弹出窗口阻止程序已禁用)使用 Chrome 时,我在开发者控制台中收到错误“资源解释为文档,但使用 MIME 类型应用程序/pdf 传输”,并且页面作为文件下载。

【问题讨论】:

    标签: asp.net windows pdf


    【解决方案1】:

    我认为应该是

     Response.AddHeader("Content-Disposition", "attachment; filename=PDFFile.pdf")
    

    另外,我会在Response.Flush() 之后拨打Response.End()

    【讨论】:

      猜你喜欢
      • 2012-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多