带有重音+ IE8的ASP MVC3 FileResult - 有问题吗?

Ako*_*acs 5 diacritics internet-explorer-8 fileresult asp.net-mvc-3

如果文件名包含重音符号,则它在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 = context.HttpContext.Request.Browser;
        if (b != null && b.Browser.Equals("ie", StringComparison.OrdinalIgnoreCase) && b.MajorVersion <= 8)
        {
            context.HttpContext.Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + HttpUtility.UrlPathEncode(base.FileDownloadName) + "\"");
            WriteFile(context.HttpContext.Response);
        }
        else
        {
            base.ExecuteResult(context);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Dar*_*rov 2

尝试在控制器操作中添加以下行:

Response.HeaderEncoding = Encoding.GetEncoding("iso-8859-1");
Run Code Online (Sandbox Code Playgroud)

您可以查看以下讨论这些问题的博客文章。不幸的是,没有一个适用于所有浏览器的通用解决方案。