【问题标题】:Internet explorer shows gibberish for save/open file?Internet Explorer 显示保存/打开文件的乱码?
【发布时间】:2015-08-19 07:32:41
【问题描述】:

我有这个从服务器下载文件的 C# 代码:

 public static void DownloadBinaryFile(byte[] _ByteArray, string fullfileName)
        {
             fullfileName = "רועי.pdf"; //"Royi.pdf" in hebrew
             System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + fullfileName);
             System.Web.HttpContext.Current.Response.BinaryWrite(_ByteArray);
             System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
             System.Web.HttpContext.Current.Response.Flush();
             System.Web.HttpContext.Current.Response.End();
        }

注意文件名有一个固定值(用于测试)。

当我点击一个按钮时:

我确实在 FIDDLER 中看到了正确的名称:

Chrome 确实显示了要保存的正确文件名:

但是 Internet Explorer 显示乱码:

附加信息:

IE 11,Windows 7 64 位,边缘:

页面编码:

问题:

为什么文件名显示为乱码,我该如何解决?

【问题讨论】:

    标签: c# asp.net http internet-explorer fiddler


    【解决方案1】:

    因为您不能在没有额外转义的情况下在 Content-Disposition 中使用非 ASCII 字符。见http://greenbytes.de/tech/webdav/rfc6266.html#disposition.parameter.filename

    【讨论】:

    • 谢谢。It is now working as expected。我添加了contentDisposition = "attachment;filename*=UTF-8''" + Uri.EscapeDataString(fullfileName);
    猜你喜欢
    • 1970-01-01
    • 2014-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-20
    • 1970-01-01
    相关资源
    最近更新 更多