不同的浏览器需要特殊设置,主要是火狐比较特殊,火狐可能给文件名加上“%0d%0a"这样的编码字符(换行的意思)。不得不佩服网上的高手,这也能解决。

 1 [HttpGet]
 2 public FileResult Download(string id)
 3 {
 4      var document = service.GetDocument(id);
 5      var fullName = Path.Combine(Root, document.FullName);
 6      string browser = HttpContext.Request.UserAgent.ToUpper();
 7      var fileName = document.Name;
 8      if (browser.Contains("FIREFOX"))
 9           fileName = "=?UTF-8?B?" + Convert.ToBase64String(Encoding.UTF8.GetBytes(fileName)) + "?=";
10      else
11           fileName = HttpUtility.UrlEncode(fileName, Encoding.UTF8);
12      return File(fullName, document.ContentType, fileName);
13 }

对于火狐的处理(标红的代码),我也是醉了,根本没看懂,但问题解决了!

【参考文献】http://www.cnblogs.com/godtrue/p/4333262.html

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
  • 2021-11-24
猜你喜欢
  • 2021-08-27
  • 2022-12-23
  • 2021-07-03
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
  • 2021-12-25
相关资源
相似解决方案