【发布时间】:2014-07-24 21:47:50
【问题描述】:
我有一个 ASP.NET MVC 4 站点,它使用 OPEN XML SDK 创建一个 excel 文件。我只是将超链接指向正确的控制器,它会生成 OPEN XML excel 文档并将流写入响应头并完成。在 IE 9 和 Chrome 中,这可以正常工作。使用给定的文件名和正确的内容下载文件。但是,就在最近,我将浏览器升级到 IE 10,现在我没有下载文件并在 excel 中打开,而是收到 could not open 'URI' 的错误。当我单击确定时,它会出现另一个错误:Microsoft Excel cannot access the file 'URI'. There are several possible reasons:
我不明白为什么这在 IE 9 和 chrome 中有效,而在 IE 10 中无效。我用提琴手调试了响应标头,它具有正确的内容类型和内容长度设置:
Content Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Content Disposition: attachment; filename=result.xlsx
Content length: 1232
我有什么遗漏的吗?
代码 sn-p:这都是
的一部分public override void ExecuteResult(ControllerContext context)
{
...
....
..
extention = "xlsx";
response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
response.AddHeader("Content-Disposition",
String.Format("attachment; filename={0}.{1}", fileName, extention));
response.AddHeader("Content-Length", mem.Length.ToString());
mem.Seek(0, SeekOrigin.Begin); // Go back to the begining.
mem.CopyTo(response.OutputStream);
context.HttpContext.ApplicationInstance.CompleteRequest();
}
【问题讨论】:
-
您是否通过 SSL 传送内容?另外,它列出了几个可能的原因?
-
writes the stream to response header and done,你能显示代码吗? -
请包含您正在使用的代码的最小示例
-
请显示一些代码...这个答案为我解决了类似的问题:stackoverflow.com/questions/16655566/ie-10-file-download-issues
-
@xDaevax:我在没有 SSL 的情况下看到了同样的问题。我没有说任何可能的原因。
标签: c# asp.net-mvc-4 internet-explorer internet-explorer-10 openxml-sdk