content-disposition attachment filename 在Firefox和IE中得到不同的结果

简介:
在Firefox中需要把filename 用双引号包起来,才能得到想要的名字,不然如果含有空格,会丢掉空格后面的部分。
而IE会把空格转为_,因此也需要 HttpUtility.UrlPathEncode方法处理下名字。
如果Firefox中也用 HttpUtility.UrlPathEncode处理名字,空格将被替换成"%20".

复制代码
 1             HttpContext.Current.Response.Buffer  =   true ;
 2             HttpContext.Current.Response.ClearContent();
 3             HttpContext.Current.Response.ClearHeaders();
 4             HttpContext.Current.Response.ContentType  =   " Application/pdf " ;
 5              string  doc1  =  System.IO.Path.GetFileNameWithoutExtension(doc)  +   " _ "   +  intNewID.ToString()  +   " .pdf " ;
 6             
 7              if (HttpContext.Current.Request.Browser.Browser  !=   " IE " )
 8                 HttpContext.Current.Response.AddHeader( " Content-Disposition " " attachment;filename=\ ""  +doc1+ " \ "" );
 9              else
10             HttpContext.Current.Response.AddHeader( " Content-Disposition " " attachment;filename= " +  HttpUtility.UrlPathEncode( doc1));
11              byte [] buffer = System.IO.File.ReadAllBytes(doc);
12             HttpContext.Current.Response.AddHeader( " Content-Length " , buffer.Length.ToString());
13             HttpContext.Current.Response.BinaryWrite(buffer);
复制代码本文转自RubyPdf 的中文博客博客园博客,原文链接:http://www.cnblogs.com/hardrock/archive/2006/09/23/512605.html/,如需转载请自行联系原作者

Firefox does not handle filenames with spaces . When a user clicks on an attachment with spaces, the filename is truncated to the first whitespace. While IE & Safari both handle this, Firefox refuses to accept mime headers with unquoted filename parameters. According to Firefox's bugzilla/knowledgebase, Firefox's behavior is the correct behavior and it's a problem with most webservers or web applications. This problem can be easily corrected by surrounding the filename parameter with double quotes.

 

 

 

相关文章
|
9月前
|
Web App开发 JavaScript
JS 获取当前浏览器类型(IE、Chrome、Edge、Firefox、Opera、UC、QQ)
JS 获取当前浏览器类型(IE、Chrome、Edge、Firefox、Opera、UC、QQ)
881 0
|
11月前
|
Web App开发 前端开发
区分IE6,IE7,IE8,IE9,FireFox,Chrome浏览器的CSS hack
区分IE6,IE7,IE8,IE9,FireFox,Chrome浏览器的CSS hack
|
Web App开发 安全
接口框架中WebDriver启动IE、Firefox和Chrome浏览器
接口框架中WebDriver启动IE、Firefox和Chrome浏览器
接口框架中WebDriver启动IE、Firefox和Chrome浏览器
|
Web App开发 数据安全/隐私保护
&nbsp在IE和FireFox中显示不一致
在做新闻发布系统后台登陆界面时,为了界面美观,想在“密码”二字中间添加空格,从而让“用户名”、“密 码”、“验证码”垂直对齐。
&nbsp在IE和FireFox中显示不一致
|
Web App开发 前端开发 JavaScript
XMLHttpRequest对象在IE和Firefox中创建方式有没有不同?
XMLHttpRequest对象在IE和Firefox中创建方式有没有不同?
141 0
|
Web App开发 前端开发 JavaScript
怎么让CSS兼容IE和FireFox火狐的技巧大全
CSS对浏览器的兼容性有时让人很头疼,或许当你了解当中的技巧跟原理,就会觉得也不是难事,从网上收集了IE7,6与Fireofx的兼容性处理 方法并整理了一下。对于web2.0的过度,请尽量用xhtml格式写代码,而且DOCTYPE 影响 CSS 处理,作为W3C的标准,一定要加 DOCTYPE声明。
1153 0
|
Web App开发 前端开发 JavaScript
最全的CSS浏览器兼容问题整理(IE6.0、IE7.0 与 FireFox)
CSS对浏览器的兼容性有时让人很头疼,或许当你了解当中的技巧跟原理,就会觉得也不是难事,从网上收集了IE7,6与Fireofx的兼容性处理方法并整理了一下.对于web2.0的过度,请尽量用xhtml格式写代码,而且DOCTYPE 影响 CSS 处理,作为W3C的标准,一定要加DOCTYPE声名. CSS技巧1.div的垂直居中问题vertical-align:middle; 将行距增加到和整个DIV一样高 line-height:200px; 然后插入文字,就垂直居中了。
1171 0