PDF 在 IE6 和 IE7 中使用 https 时出现错误
Response.Write("<script language=\"javascript\">window.open( with https and pdf
我们在 Asp.Net 1.1.4332 应用程序中执行的操作如下:
按钮触发服务器事件,该事件执行一些处理并将数据放入会话对象中,然后执行以下代码:
string page = Request.ApplicationPath + "/ApkRapportPage.aspx";
Response.Write("<script language=\"javascript\">window.open('" + page + "','_new');</script>");
这将打开一个流式传输 pdf 的页面 基本上使用以下代码到新的浏览器窗口
(我知道这里缺少一些东西,但这对问题来说并不重要)
byte[] pdfbytes = Convert.FromBase64String(rapportB64);
Response.ClearContent();
Response.ClearHeaders();
Response.Buffer = true;
Response.ContentType = GetContentType(format);
string header = GetContentDispostionHeader(fileName, format, type);
Response.AddHeader("Content-Disposition", header);
Response.BinaryWrite(pdfbytes);
Response.End();
好的,这段代码可以工作!
只是在使用 HTTPS 时不适用于 IE6 和 IE7
当使用带有 HTTPS 的 IE6 时,会出现一个“另存为”对话框(不是在浏览器中打开的 pdf) ) 当使用带有 HTTPS 的 IE7 时,会导致黑屏 使用 Firefox 时,它工作得很好
如果我在 page_load 中模拟额外的服务器端处理,将所需的数据放入会话中,并将按钮替换为在新窗口中打开相同 pdf 生成页面的链接,则代码可以工作。
对于实际应用程序,在单击按钮之前无法获取所需数据。
所以我真的很想让下面的代码工作
string page = Request.ApplicationPath + "/ApkRapportPage.aspx";
Response.Write("<script language=\"javascript\">window.open('" + page + "','_new');</script>");
问题: 有谁知道为什么使用 HTTPS 时此代码在 IE6 和 IE7 中不起作用? 需要什么才能使代码正常工作?
额外信息:
- 我尝试不使用response.write但是 只是一个javascript window.open 后面 按钮,这
- 在谷歌搜索 pdf 流时具有相同的效果,你可以发现很多人都有 遇到这个问题,大多数情况下他们设置 标头长度或其他属性或 IIS 中的静态文件压缩标志。 我非常有信心我尝试过 全部。
- Adobe acrobat reader 设置、浏览器设置或任何其他客户端 侧面设置似乎不是 问题。 在不同的平台上测试过 机器,使用http可以工作,使用https 事实并非如此。
- https 和 http 之间的切换可能与此有关, 但是当我设置 IE 告诉我什么时候 正在切换,似乎没有切换 测试期间发生。
- 当用response.redirect替换window.open部分时,代码也可以工作,只是不在新窗口中
任何帮助将不胜感激!
根据请求的标头,如 Fiddler 所示:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Thu, 05 Mar 2009 14:18:36 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Content-Disposition: Inline;filename=APKrapport.pdf
Cache-Control: private
Content-Type: application/pdf; charset=utf-8
Content-Length: 28307
Response.Write("<script language=\"javascript\">window.open( with https and pdf
What we do in a Asp.Net 1.1.4332 application is the following:
a button triggers a server event that does some processing and puts the data in a session object after that the following code is executed :
string page = Request.ApplicationPath + "/ApkRapportPage.aspx";
Response.Write("<script language=\"javascript\">window.open('" + page + "','_new');</script>");
this opens a page that streams a pdf to the new browser window
basically with the following code ( I know stuff is missing here, but that doesn't really mater for the question)
byte[] pdfbytes = Convert.FromBase64String(rapportB64);
Response.ClearContent();
Response.ClearHeaders();
Response.Buffer = true;
Response.ContentType = GetContentType(format);
string header = GetContentDispostionHeader(fileName, format, type);
Response.AddHeader("Content-Disposition", header);
Response.BinaryWrite(pdfbytes);
Response.End();
Okay this code works !
Just not in IE6 and IE7 when using HTTPS
When using IE6 with HTTPS it results in a save-as dialog (not a pdf that opens in a browser)
When using IE7 with HTTPS it results in a blank screen
When using Firefox it works just fine
If I simulate the extra server side processing in the page_load to put the required data in the session and replace the button with a link that opens the same pdf generating page in a new window, the code works.
For the actual application it is not an option to get the required data before the button is clicked.
So I would really like to get the following code to work
string page = Request.ApplicationPath + "/ApkRapportPage.aspx";
Response.Write("<script language=\"javascript\">window.open('" + page + "','_new');</script>");
Questions:
Does anybody know why this code doesn't work in IE6 and IE7 when using HTTPS ?
What is needed to get the code to work ?
Extra info:
- I tried not using response.write but
just a javascript window.open behind
the button, this has the same effect - when googling for pdf streaming, you can find a lot of people having
trouble with this, mostly they set
header lengths or other properties or
static file compression flags in IIS.
I am pretty confident I tried them
all. - Adobe acrobat reader settings, browser settings or any other client
side settings don't seem to be the
problem. Tested on different
machines, with http works, with https
it doesn't. - Switching between https and http might have something to do with this,
but when I set IE to tell me when I
am switching, no switching seems to
occur during testing. - When replacing the window.open part with a response.redirect then the code also works, just not in a new window
Any help would be greatly appreciated !
As requested the headers, as shown by Fiddler:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Thu, 05 Mar 2009 14:18:36 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Content-Disposition: Inline;filename=APKrapport.pdf
Cache-Control: private
Content-Type: application/pdf; charset=utf-8
Content-Length: 28307
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
让附件以您想要的方式打开与您发送的标头密切相关。 如果您找到想要充当动态 PDF 资源的 .aspx 页面,这些 HTTP 标头将变得越来越重要。
此网站说明了它在 IE 中无法运行的多种原因。
http://xyz/DoGenCompStmt?filename=dummy.pdf
因为 IE 忽略内容类型,所以你需要给它一个提示,“.pdf”扩展名是一个简单的方法。
编辑:由于您已经尝试了上述所有操作,我只能将您指向
编辑:真正有帮助的是当您尝试在浏览器中打开 pdf 时查看它当前返回的 HTTP 标头。 Fiddler 在捕获流量方面做得很好
Getting attachments to open the way you want has everything to do with the headers you send. If you locate to an .aspx page that you want to act as a dynamic PDF resource these HTTP headers become increasingly important.
This website states a number of reasons why it might not work in IE.
http://x.y.z/DoGenCompStmt?filename=dummy.pdf
because IE ignores content-types, so you need to give it a hint, and the ".pdf" extension is an easy way.
EDIT: since you already tried all of the above i can only point you to the rfc for content disposition which to my knowledge is the only way to tell a browser how to deal with binary content.
EDIT: what would really help is to see the HTTP Headers it currently returns when you try to open the pdf in the browser. Fiddler does a great job at catching traffic
您最好使用通用处理程序 (.ASHX) 来提供此类内容,而不是尝试强制网页提供 HTML 以外的内容。
You'd be better off using a generic handler (.ASHX) to serve this sort of content, rather than trying to force a web-page to serve content other than HTML.
经过大量的试验和错误,我找到了一个可行的解决方案,但仍然不确定为什么其他代码不起作用。
此代码有效:
必须与 mime 类型有关。
但它有一个问题。 当 IE 设置为在 HTTP 和 HTTPS 之间切换时显示时,此代码将显示该消息两次。 以下代码不会切换,但会导致 ApkRapportPage 的页面加载被触发两次。
After a lot of trial and error I found a working solution, still not sure why the other code doesn't work.
This code works:
Must have something to do with the mime type.
It has a problem though. When IE is set to show when you switch between HTTP and HTTPS this code will give that message twice. The following code doesn't switch but causes the page load of ApkRapportPage to be fired twice.
如果您在 IE7 浏览器中尝试查看内联 PDF 时出现空白页面,并且您使用的是 Acrobat 版本 6。请更新您的 Acrobat 版本以解决问题。
If you are getting a blank page when trying to view a PDF inline in the IE7 browser and you are using Acrobat version 6. Update your Acrobat version to resolve problem.
请注意,此问题与 HTTPS 无关,同样的问题(以及相同的修复)也适用于 HTTP。
该修复之所以有效,是因为 IE 的问题是,如果立即加载 PDF,它不会在脚本打开的窗口中显示 PDF。 (原因不明,但这是问题的核心,也是解决办法。)
Note that this problem is unrelated to HTTPS, the same problem (and the same fix) applies for HTTP.
The fix works because the problem with IE is that it doesn't display PDF in a script-opened window if the PDF is loaded at once. (Unknown why, but this is the core of the problem, and the fix.)
我注意到您返回的内容类型是
“Content-Type: application/pdf; charset=utf-8”
当您将内容流式传输到 aspx 页面时,请确保您设置
I notice that your returned content-type is hosed
"Content-Type: application/pdf; charset=utf-8"
When you stream the content to the aspx page ensure that you set the