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();

上一篇:C语言的数据类型


下一篇:零基础学习Hadoop