在FireFox/IE下Response中文文件名乱码问题解决方案

(编辑:jimmy 日期: 2024/10/6 浏览:2)

发现很多园子里的人在处理Response下载文件名是使用这个方法
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileInfo.Name, System.Text.Encoding.UTF8));
但这个只是针对没有空格和IE的情况下使用。

如果想在FireFox下输出没有编码的文件,并且IE下输出的文件名中空格不为+号,就要多一次判断了。
复制代码 代码如下:
if (Request.UserAgent.ToLower().IndexOf("msie") > -1)
{
downloadfilename = HttpUtility.UrlPathEncode(downloadfilename);
}
if (Request.UserAgent.ToLower().IndexOf("firefox") > -1)
{
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + downloadfilename + "\"");
}
else
{
Response.AddHeader("Content-Disposition", "attachment;filename=" + downloadfilename);
}
一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。