惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Security Blog
Microsoft Security Blog
Jina AI
Jina AI
量子位
博客园 - 叶小钗
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
S
SegmentFault 最新的问题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
雷峰网
雷峰网
博客园 - 聂微东
美团技术团队
Last Week in AI
Last Week in AI
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园_首页
V
Visual Studio Blog
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog

博客园 - RubyPDF

Google Voice开始发送邀请函 ASP.NET空间使用SQLite遇到的麻烦 PDF数字签名免安装版本发布-Portable PDF Digital Signature(Portable PDF Signer) Dreamhost 开始提供免费空间了 SQLite Manager Sqlite使用中的几点体会。 Thinkpad T60 Fan Error及重新启动windows后画面静止 PdfCrypt 1.0 for Windows 发布 XMP Remover:批量删除PDF 文档的XMP data 软件正版化要靠政府,不能靠国产软件 FCrackZip 1.0 Windows 版本发布 破解MS Word 的只读密码限制 PDFCrack 0.11 Windows 版本发布 Chrome 的又一个bug? 服务器端动态序列化与Unable to generate a temporary class报错 OpenOffice 3增加PDF导入和编辑功能 AspSpider 终止提供免费空间服务了。 比尔盖兹在某个大学毕业典礼上的演讲中,对毕业生提出十一项极为睿智的人生建议 在博客页首添加搜索功能
content-disposition attachment filename 在Firefox和IE中得...
RubyPDF · 2009-09-30 · via 博客园 - RubyPDF

在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);

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.