正如评论中的namesv所说,这似乎对IE9根本不可行。我终于通过滥用浏览器功能解决了这个问题:当它请求类似的东西/foo/fileÄÖ.pdf
并返回一个文件时,使用 URL 中的“文件名”。
因此,我创建了一条新路线,将我的动态下载定位到它并在操作中执行此操作:
if (Request.Browser.Browser == "IE" && Request.Browser.MajorVersion == 9)
{
// The filename comes from the Route used, which is like host/Print/File.pdf
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment");
Response.ContentType = System.Net.Mime.MediaTypeNames.Application.Octet;
Response.Charset = "utf-8";
Response.HeaderEncoding = UnicodeEncoding.UTF8;
Response.ContentEncoding = UnicodeEncoding.UTF8;
byte[] buffer = new byte[4096];
int count = 0;
while ((count = stream.Read(buffer, 0, buffer.Length)) > 0)
{
Response.OutputStream.Write(buffer, 0, count);
Response.Flush();
}
Response.End();
return null;
}
else
{
return File(
fileStream: stream,
contentType: System.Net.Mime.MediaTypeNames.Application.Octet,
fileDownloadName: compilation.Name + "." + pub.OutputFileType);
}