content-disposition attachment filename 在Firefox和IE中得到不同的结果
在Firefox中需要把filename 用双引号包起来,才能得到想要的名字,不然如果含有空格,会丢掉空格后面的部分。
而IE会把空格转为_,因此也需要HttpUtility.UrlPathEncode方法处理下名字。
如果Firefox中也用HttpUtility.UrlPathEncode处理名字,空格将被替换成"%20".
1 HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ContentType = "Application/pdf";
string doc1 = System.IO.Path.GetFileNameWithoutExtension(doc) + "_" + intNewID.ToString() + ".pdf"; if(HttpContext.Current.Request.Browser.Browser != "IE")
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"" +doc1+"\"");
else
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename="+ HttpUtility.UrlPathEncode( doc1));
byte[] buffer=System.IO.File.ReadAllBytes(doc);
HttpContext.Current.Response.AddHeader("Content-Length", buffer.Length.ToString());
HttpContext.Current.Response.BinaryWrite(buffer);
content-disposition attachment filename 在Firefox和IE中得到不同的结果的更多相关文章
- 【转】解决response.AddHeader("Content-Disposition", "attachment; fileName=" + fileName) 中文显示乱码
如果fileName为中文则乱码.解决办法是 方法1: response.setHeader("Content-Disposition", "attachment; fi ...
- 解决Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name) 中文显示乱码
如果file.Name为中文则乱码.解决办法是方法1:response.setHeader("Content-Disposition", "attachment; fil ...
- C#中解决Response.AddHeader("Content-Disposition", "attachment; filename=" + filename)下载文件时文件名乱码的问题
问题:下载文件时文件名乱码怎么解决? 在C#写后台代码过程中,经常遇到下载文件出现文件名乱码的问题,在网上找了很多方法,总是存在浏览器不兼容的问题,当IE浏览器不乱码时,火狐浏览器就会乱码,后来经过反 ...
- Response attachment filename 中文乱码
Response.setHeader("Content-Disposition", "attachment; filename=" + fileName+&qu ...
- Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name) 中文显示乱码
如果file.Name为中文则乱码.解决办法是方法1:response.setHeader("Content-Disposition", "attachment; fil ...
- 文件下载:"Content-disposition","attachment; filename=中文名>>>解决方案
文件下载时常会出现如下问题: response.setHeader("Content-disposition","attachment; filename="+ ...
- response.setHeader("Content-disposition","attachment;filename="+fileName) 下载时文件名中存在空格错误
最近在进行文件下载时发现一个问题,就是下面语句运行时,下载某些文件正常,下载某些文件异常,后来发现文件名中有空格的文件火狐浏览器是默认将文件名截断了的 response.setHeader(" ...
- firfox中"content-disposition", "attachment;filename=“+filename不能显示文件名字
一般要在浏览器中显示文件名,可以使用以下文件名 // 设置文件名的编码方式,使得文件的名字能够正常安全的显示. filename = URLEncoder.encode(filename, " ...
- 使用response.setHeader("Content-Disposition","attachment;filename="+fName)下载文件,中文文件名无法显示的问题
今天遇到这么一个情况,在Action代码中进行文件下载: ActionForm得到file_id,通过file_id进行数据库查询得到file_name以及服务器硬盘上的file_uri,其中file ...
随机推荐
- Symfony 如何使用ckeditor
首先: 1)加载以下两个bundle "egeloen/ckeditor-bundle": "^4.0","helios-ag/fm-elfinder ...
- python3的时间日期处理
1.python3日期和时间 Python 程序能用很多方式处理日期和时间,转换日期格式是一个常见的功能. Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间. 时 ...
- 保护眼睛,win7家庭版如何修改窗口的背景颜色
win7的窗口背景色为白色,长时间使用电脑对眼睛的刺激比较大,为了保护眼睛建议改成浅灰色或者淡绿.淡黄色等,可是win7的家庭版里没有[个性化]菜单,那么我们如何修改呢? 首先在[开始]处找到[控制面 ...
- IntelliJ IDEA(2017)安装和破解(转发)
IntelliJ IDEA(2017)安装和破解 IDEA 全称 IntelliJ IDEA,是Java语言开发的集成环境,IntelliJ在业界被公认为最好的java开发工具之一,尤其在智能代码助手 ...
- 每天一个Linux命令(8)cat命令
cat命令连接文件并打印到标准输出设备上,cat经常用来显示文件的内容,类似于下的type命令. 注意:当文件较大时,文本在屏幕上迅速闪过(滚屏),用户往往看不清所显示的内容.因此,一般用more等命 ...
- StartUML如何画“不折弯”的直线
将下图中line style改成 OBlique.快捷键Ctrl +B
- [转]eclipse中的常用快捷键
1.选中你要加注释的区域,用ctrl+shift+C 会加上//注释2.先把你要注释的东西选中,用shit+ctrl+/ 会加上注释3.要修改在eclispe中的命令的快捷键方式我们只需进入windo ...
- pulseaudio备注
参考http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?viewmode=compact&topic_id=10102 Ubuntu 8. ...
- web框架详解之tornado 一 模板语言以及框架本质
一.概要 Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像web.py 或者 Google 的 webapp,不过 ...
- 剑指offer——求1+2+...+n
方法一.通过在类的构造函数中执行加的过程. #include <iostream> using namespace std; class Base { public: Base(){n++ ...