我有一个 .aspx 页面,我在其中手动设置标题以强制下载 pdf 文件。它在 IE 中运行良好,但在 chrome 和 firefox 8.0 中,它给出了一个错误。
我终于找到了问题的根源,因为 content-disposition 标头被发送了两次,但我不知道第一次是如何设置或为什么设置它的。
头的第一个实例就是:Content-disposition:Attachment 第二个是:Content-Disposition:attachment; filename=download.pdf <-- 这个由代码设置
IIS 是否以某种方式接管并添加标头的第一个实例?如果是这样,我怎样才能将其切换为不这样做?
编辑:添加设置标题的代码
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
Response.WriteFile(fname);
Response.Flush();
Response.End();