中文文件名下载在火狐乱码

我们一般下载中文文件名一般会utf-8编码再下载,火狐浏览器会出现文件名乱码,解决办法,火狐浏览器文件名不编码,直接下载:

   HttpContext curContext = HttpContext.Current;

            // 设置编码和附件格式
            curContext.Response.ContentType = "application/vnd.ms-excel";
            curContext.Response.ContentEncoding = Encoding.UTF8;
            curContext.Response.Charset = "";
            strFileName = strFileName + DateTime.Now.ToString("yyyyMMddHHmmss");

            string userAgent = curContext.Request.ServerVariables["http_user_agent"].ToLower();
            if (userAgent.IndexOf("firefox", StringComparison.Ordinal) == -1) 
            {
                strFileName = HttpUtility.UrlEncode(strFileName, Encoding.UTF8) + ".xls";
            }
            curContext.Response.AppendHeader("Content-Disposition",
                "attachment;filename=" + strFileName);

            curContext.Response.BinaryWrite(ListToExcel(list, strFileName, titleDic).GetBuffer());
            curContext.Response.End();

 

posted @ 2019-02-22 14:55  _York  阅读(1673)  评论(0编辑  收藏  举报