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 ...
随机推荐
- ThinkPHP5.0 用docker部署
Dockerfile 文件如下: FROM hub.c.163.com/shenggen/thinkphp-docker:v0.0.1 ADD . /app RUN ["chmod" ...
- oracle decode的用法
需求:分别统计emp表中1980,1981,1982,1987年入职的同事的数量. 这里用decode很容易就解决了: select sum(t.num_1980) as "1980&quo ...
- sin6_addr打印:string to sockaddr_in6 and sockaddr_in6 to string
函式原型: #include <arpa/inet.h> const char *inet_ntop(int af, const void *src, char *dst, socklen ...
- 数据库存储I/O类型分析与配置
存储设备作为数据的容器,为应用提供数据存取服务,而存储系统将数据展现给不同的应用后,应用程序对数据访问不尽相同.简要来说,就是读和写,更加细分的话是以不同的传输单元(I/O大小)进行顺序和随机类型的读 ...
- 获取comboBox里面的item使用的方法
使用currentIndex()或者currentText() void Widget::calc() { int first = ui->firstLineEdit->text().to ...
- DatagramSocket总是发送UDP数据后无法接收数据
ref:http://blog.chinaunix.net/uid-20771867-id-3416509.html cmd:telnet localhost 5554 ...
- 3.25课·········JavaScript的DOM操作
1.DOM的基本概念 DOM是文档对象模型,这种模型为树模型:文档是指标签文档:对象是指文档中每个元素:模型是指抽象化的东西. 2.Window对象操作 一.属性和方法: 属性(值或者子对象): op ...
- flex 坐标系
全局坐标(舞台坐标) 本地坐标 内容坐标系 地图坐标(MapPoint) flash和flex针对不同的目的,提供了3种不同的坐标系 全局的就是(stage级别的) 本地坐标系(组件级别的) 内容 ...
- mysql自定义函数语法
创建函数 DELIMITER $$DROP FUNCTION IF EXISTS `test` $$CREATE FUNCTION `test`(a int ,b int)RETURNS int BE ...
- Luogu-4196 [CQOI2006]凸多边形
凸多边形的面积就相当于半平面交 求几个凸多边形面积交就相当于一堆半平面一起求交 #include<cmath> #include<cstdio> #include<cst ...