我有一个页面,当用户点击按钮时,会动态生成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无法打开此网站。所请求的站点不可用或无法找到。请稍后再试"。
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