【发布时间】:2010-11-12 09:31:15
【问题描述】:
我有一个页面,当用户单击按钮时,会动态生成 PDF 并提供给他们下载。
这是让用户下载 pdf 的代码:
// Omitted code that generates the pdf bytes
response.ContentType = "application/octetstream";
response.AppendHeader("Content-Disposition", "attachment; filename=" + filename);
response.BinaryWrite(pdfBytes);
response.End();
在我的机器和许多其他混合使用 Chrome、IE 7/8/9b 和 Firefox 的机器上,这按预期工作;用户点击按钮,PDF 被下载。
在某些 IE7 实例中,我们的用户报告他们收到错误消息:
“Internet Explorer 无法从 thesite.com 下载 Publish.aspx
Internet Explorer 无法打开此 Internet 站点。请求的站点不可用或找不到。请稍后再试”。
Publish.aspx 是按钮所在的页面,因此该页面 可用。 IE 应该正在下载 pdf。
上面的代码有什么问题可能导致某些机器上出现这种情况吗?还是取决于特定的安全/操作系统/浏览器设置?
编辑:
这些是来自 fiddler 的响应标头:
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Content-Type: application/octetstream
Expires: -1
Server: Microsoft-IIS/7.5
Content-Disposition: attachment; filename=myPdf.pdf
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Fri, 12 Nov 2010 09:48:06 GMT
Content-Length: 45772
【问题讨论】:
-
很高兴看到所有响应头。
-
已编辑以包含响应标头