2012-07-13 47 views
0

我有一个返回PDF的.aspx页面。以下是Page_PreRender上的代码。ASPX页面无法在IE7和Windows XP上呈现PDF格式

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调用启动的。

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

回答

1

我相信它应该是

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

另外,我会打电话Response.End()刚过Response.Flush()