2

我一直试图让这个 aspx 页面提供一个 pdf。它在 Firefox 中正常工作,但 IE 提供

Internet Explorer 无法从 SERVER_NAME 下载 getform.aspx
Internet Explorer 无法打开此 Internet 站点。请求的站点不可用或找不到。

这是我的代码的一般功能。它分布在多个函数中(这就是我们不使用 WriteFile 的原因 - 有时我们会即时生成 pdf),但通常是这样的:

FileStream fs = File.Open(Path.Combine(PdfBasePath, "form.pdf"), FileMode.Open, FileAccess.Read);
Stream output = Response.OutputStream;

byte[] buffer = new byte[BUFFER_SIZE];
int read_count = fs.Read(buffer, 0, BUFFER_SIZE);
while (read_count > 0)
{
    output.Write(buffer, 0, read_count);
    read_count = fs.Read(buffer, 0, BUFFER_SIZE);
}

fs.Close();

Response.Clear();
Response.ContentType = System.Net.Mime.MediaTypeNames.Application.Pdf;
Response.AddHeader("Content-Disposition", "attachment; filename=form.pdf");
Response.Output.Flush();
Response.End();

查看 Fiddler,正在使用以下方法获取页面:

GET /getform.aspx?Failure=Y&r=someencryptedstring HTTP/1.1

它因此被返回到浏览器:

HTTP/1.1 200 OK
日期:2009 年 4 月 9 日星期四 22:08:33 GMT
服务器:Microsoft-IIS/6.0
X-Powered-By:ASP.NET
X-AspNet-Version:2.0.50727
Pragma:no-cache
Content-处置:附件;filename=form.pdf
Cache-Control: no-cache, no-store
Pragma: no-cache
Expires: -1
Content-Type: application/pdf
Content-Length: 628548

这真的让我很烦。我没有使用 SSL,否则这篇知识库文章似乎适用。有人有想法么?

4

1 回答 1

1

标头中返回的 Content-Length 对于您发送的文件是否真的正确?我只是将它与我​​们在这里使用的一些生产代码进行比较,看起来我们明确设置了 Content-Length 标头。如果我没记错的话,如果标题和实际文件大小不匹配,某些浏览器会出现问题。

编辑 问题作者发现将 Content-Disposition 标头更改为 application/download 而不是 application/pdf 似乎可以解决该问题。

于 2009-04-09T23:14:18.697 回答