我有一个MVC .Net应用程序,它具有返回报告文件的操作,通常.xslx:
byte[] data = GetReport();
return File(data,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"filename.xlsx");
Run Code Online (Sandbox Code Playgroud)
这在测试和所有浏览器中都很有用,但是当我们把它放在一个SSL站点上时,IE6,7和8(所有正确的浏览器仍能正常工作)失败,这个无用的错误:

这曾经用于此操作替换的遗留应用程序(非MVC).
我们无法告诉用户在本地更改任何内容 - 大约60%仍在IE6上!
我如何使用MVC解决这个问题?
进一步的挖掘表明,这是IE6-8中的一个根本性失败.根据Eric Law的IE internals博客,这是因为在SSL连接期间,IE将no-cache指令视为绝对规则.因此,它不考虑缓存副本,而是认为no-cache意味着即使在Content-Disposition:attachment显式提示下载位置时也不可能将副本保存到磁盘
.
显然这是错误的,但是当它在IE9中得到修复时,我们仍然坚持使用所有的IE6-8用户.
使用MVC的操作过滤器属性会生成以下标头:
Cache-Control:no-cache, no-store, must-revalidate
Pragma:no-cache
Run Code Online (Sandbox Code Playgroud)
使用Fiddler动态更改这些,我们可以验证需要返回的标头:
Cache-Control:no-store, no-cache, must-revalidate
Run Code Online (Sandbox Code Playgroud)
需要注意的顺序Cache-Control 必须有no-store 之前 no-cache与该Pragma指令必须被完全删除.
这是一个问题 - 我们广泛使用MVC的动作属性,我真的不想从头开始重写它们.即使我们尝试删除Pragma指令,IIS也会抛出异常.
你如何让微软的MVC和IIS返回微软的IE6-8可以在HTTPS下处理的无缓存指令?我不想允许私有缓存响应(根据这个类似的问题)或忽略MVC内置方法的覆盖(根据我自己的答案,这只是我目前最好的黑客).
如果文件名包含重音符号,则它在Opera,FF,Chrome和IE9中按预期工作.
但在IE8文件类型中是"未知文件类型",并显示"文件"作为文件名(实际上是URL的最后一部分).
有没有人知道解决方法?替换文件名中的"特殊"字符除外?
测试代码:(文件|新项目|添加控制器)
public class FileController : Controller
{
public ActionResult Index(bool? Accents)
{
byte[] content = new byte[] { 1, 2, 3, 4 };
return File(content, "application/octet-stream", true.Equals(Accents) ? "dsaé.txt" : "dsae.txt");
}
}
Run Code Online (Sandbox Code Playgroud)
像这样测试: http:// localhost/file, http:// localhost/file?accents = true
public class FileContentResultStupidIE : FileContentResult //yeah, maybe i am not totally "politically correct", but still...
{
public FileContentResultStupidIE(byte[] fileContents, string contentType) : base(fileContents, contentType) { }
public override void ExecuteResult(ControllerContext context)
{
var b = …Run Code Online (Sandbox Code Playgroud)