Unicode in Content-Disposition header

后端 未结 7 1396
情歌与酒
情歌与酒 2020-12-03 17:46

I am using HttpContext object implemented in HttpHandler child to download a file, when I have non-ascii characters in file name it looks weird in IE whereas it looks fine i

7条回答
  •  渐次进展
    2020-12-03 18:33

    For Asp.Net Core (version 2 as of this post) UrlPathEncode is deprecated, here's how to achieve the desired result:

    System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
    {
       FileName = Uri.EscapeUriString(fileName),
       Inline = true  // false = prompt the user for downloading;  true = browser to try to show the file inline
    };
    
    Response.Headers.Add("Content-Disposition", cd.ToString());
    

提交回复
热议问题