信息发布→ 登录 注册 退出

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

发布时间:2026-01-11

点击量:
发现很多园子里的人在处理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);
}
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!