问题描述
我在ASPNET MVC返回一个FileContentResult的动作。我注意到,当fileDownloadName包含变音(即亚洲开放大学协会)Internet Explorer无法在所有读取的文件名。
我已经试过URL编码:
返回this.File(document.Content,则contentType,Server.UrlEn code(document.Name));
但随后所有的空格用加号(+)取代。
有没有办法让UNI code文件名与IE浏览器(保持原文件名不变)?
这是我目前使用作为一个黑客:
返回this.File(
document.Content,
内容类型,
Server.UrlEn code(document.Name).Replace('+',''));
(这使得空间在IE下划线)
-
UrlEn code
被误导命名,这只是形式的数据。你想UrlPathEn code
,而不是将它解决了+
问题。请参见。 -
然而,在URL编码无论如何是错误的做法在这里,你不是构造URL。它工作在IE其实是一个错误,这就是为什么你会得到
%
-sequences在其他浏览器。
不幸的是,没有可靠的跨浏览器的方式来获得非ASCII字符变成内容处置
文件名参数。在理论上它可能使用RFC 2331的规则都没有可能,但即使如此,该规范是值得商榷和现实是什么支持它。请参见。
Drop the filename
parameter from the Content-Disposition
header and instead include the filename as a trailing path part of your script's address, where it's quite valid to use URL-encoding (UTF-8 and UrlPathEncode
). eg for someaction
controller:
http://www.example.com/someaction/åäöü.txt
http://www.example.com/someaction/%C3%A5%C3%A4%C3%B6%C3%BC.txt
All browsers will offer to save the resulting file as åäöü.txt
.
这篇关于有效的文件名(下载)在IE浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!