response 下载文件火狐浏览器文件名乱码问题

 string path = Server.MapPath(Url.Content("~/") + "UploadFiles/Template/");
            
            FileStream fs = new FileStream(path + file, FileMode.Open);
            byte[] bytes = new byte[(int)fs.Length];
            fs.Read(bytes, 0, bytes.Length);
            fs.Close();
            Response.ContentType = "application/octet-stream";

            if (Request.UserAgent.ToLower().IndexOf("firefox") > -1) //火狐浏览器
            {
                Response.AddHeader("Content-Disposition", "attachment;filename="" + file + """);
            }
            else //其他浏览器
            {
                Response.AddHeader("Content-Disposition", "attachment;  filename=" + HttpUtility.UrlEncode(file, System.Text.Encoding.UTF8));
            }
            
            Response.BinaryWrite(bytes);
            Response.Flush();
            Response.End();

原文地址:https://www.cnblogs.com/workstation-nigoudongma/p/9883577.html