【问题标题】:ASP.NET 4.0, Browser binary render of PDF on IIS6ASP.NET 4.0,IIS6 上 PDF 的浏览器二进制渲染
【发布时间】:2012-11-13 18:25:11
【问题描述】:

我有一个 ASP.Net 4.0 Web 应用程序,它在客户端的浏览器上呈现使用 CrystalReports 在 iF​​rame 中通过二进制写入动态创建的 PDF。 webapp 在我的开发站(Visual Studio 2012 Web Developer)上运行良好,但是当我对我们的生产服务器(Win2003、IIS6)进行测试时,用户单击按钮以流式传输 PDF 的部分仅显示文档的一部分(仅页眉徽标,PDF 的其余部分为空白)。我做了一个测试:我没有将二进制数据流式传输到我保存到服务器虚拟路径上的本地目录的客户端浏览器中,而是可以访问完整性良好的 PDF,所有数据都出现在保存的文档上。我已经在谷歌上搜索了 3 天,尝试了各种代码 sn-ps、IIS 配置(日志文件未显示任何错误)、服务器权限、HTML 标头、web.config 标签等,但没有成功。我怀疑它与 IIS 有关,但我找不到解决方案。以下是在客户端浏览器上呈现 PDF 的代码:

//reportObject is a CrystalReport document object (.rpt)
Dim s As System.IO.MemoryStream = reportObj.ExportToStream(ExportFormatType.PortableDocFormat)

s.Seek(0, SeekOrigin.Begin)

With HttpContext.Current.Response
    .ClearContent()
    .ClearHeaders()
    .ContentType = "application/pdf"
    .AddHeader("Content-Disposition", "inline; filename=" & fileName)
    .BinaryWrite(s.ToArray)
    .Flush()
    .End()
End With

我也试过这些,都在我的开发机器上工作,但在服务器上却不行:

With HttpContext.Current.Response
            .Clear()
            .ClearHeaders()
            .Buffer = True

            .AddHeader("Content-Disposition", "inline; filename=doc.pdf")
            .AddHeader("Content-Length", Int32.Parse(s.Length))
            .AddHeader("Content-transfer-encoding", "8bit")
            .AddHeader("Cache-Control", "private")
            .AddHeader("Pragma", "cache")
            .AddHeader("Expires", "0")
            .AddHeader("X-UA-Compatible", "IE=EmulateIE7")

            .ContentType = "application/pdf"
            .BinaryWrite(s.ToArray)

            .Flush()
            .Close()
            HttpContext.Current.ApplicationInstance.CompleteRequest()
        End With

还有以下几行:

.AppendHeader("Accept-Ranges", "none")
.OutputStream.Write(s.ToArray(), 0, Convert.ToInt32(s.Length))

似乎没有任何帮助。

【问题讨论】:

    标签: asp.net iis pdf browser binary


    【解决方案1】:

    我必须实现此线程中描述的另一种方法:

    Response.TransmitFile and delete it after transmission

    我希望它对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2016-02-20
      • 1970-01-01
      • 1970-01-01
      • 2013-08-26
      • 2021-04-08
      • 1970-01-01
      • 2012-10-09
      • 2011-02-07
      • 1970-01-01
      相关资源
      最近更新 更多