【发布时间】:2017-04-19 11:40:32
【问题描述】:
我的 .mvc 应用程序试图显示一个 pdf 文件。它在IE上正常工作,但在Chrome和FF上失败,给ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION根据here和其他网站上的类似问题,这似乎是一个http头问题?当我尝试直接查看标头时,我发现发送到 IE 和 Firefox 的响应不同,因为 FF 得到 3 个响应,而 IE 得到 1 个:
IE响应头:
Response HTTP/1.1 200 OK
Cache-Control no-cache, no-store, must-revalidate
Pragma no-cache
Content-Type application/pdf
Expires 0
Server Microsoft-IIS/7.5
X-AspNetMvc-Version 4.0
Content-Disposition inline; filename="Invoice Number US123412.pdf#toolbar=1&view=FitV"
Content-Disposition attachment; filename="Invoice Number US123412.pdf"
X-AspNet-Version 4.0.30319
Persistent-Auth true
X-Powered-By ASP.NET
Date Wed, 19 Apr 2017 12:00:00 GMT
Content-Length 77107
许多人给出的解决方案是在文件名周围添加引号(“”),我这样做了,但这似乎没有任何帮助。这是我的标题编辑代码:
Response.AddHeader("Content-Disposition", "inline; filename=\"" + fileName + "#toolbar=1&view=FitV\"");
Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
Response.AppendHeader("Expires", "0"); // Proxies.
invoiceHelper.PDF = new InvoicePDF { FileBytes = renderedBytes, FileName = fileName };
return File(renderedBytes, "application/pdf", fileName);
看来我可能误解了其他线程中建议的解决方案?任何帮助将不胜感激。
编辑:
我应该注意,我还尝试将文件名更改为不包含空格,以便当前响应具有Invoice_Number_somenuber12121
编辑2:
似乎当我删除我的标头代码,而是添加esponse.ClearHeaders(); 时,网站加载但 pdf 被下载而不是显示
编辑3: 我已经找到了答案,所以我删除了这个问题中一些并不重要的部分。
【问题讨论】:
标签: asp.net asp.net-mvc http firefox http-headers