content-disposition attachment filename 在Firefox和IE中得到不同的结果
2009-09-30 08:18
489 查看
在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
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);
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.
而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
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);
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.
相关文章推荐
- content-disposition attachment filename 在Firefox和IE中得到不同的结果
- 使用Content-Disposition: attachment; filename=FILENAME,在Firefox浏览器中下载文件,文件名中文乱码问题解决。
- 文件下载时,IE与FireFox对文件名编码的不同处理! Content-Disposition
- 文件下载:"Content-disposition","attachment; filename=中文名>>>解决方案
- 解决Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name) 中文显示乱码
- response.addHeader("Content-Disposition","attachment; filename="+filename)中的中文乱码问题
- response.setHeader("Content-disposition","attachment;filename="+fileName) 下载时文件名中存在空格错误
- 解决Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name) 中文显示乱码
- 解决Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name) 中文显示乱码
- 利用response和HttP中的Content-Disposition: attachment; filename=aaa.zip响应头,实现简单的文件下载
- [转]response.addHeader("Content-Disposition","attachment; filename="+filename)中的中文乱码问题
- 文件下载:"Content-disposition","attachment; filename=中文名>>>解决方案
- 文件下载:"Content-disposition","attachment; filename=中文名>>>解决方案
- 文件下载:"Content-disposition","attachment; filename=中文名>>>解决方案
- 解决Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name) 中文显示乱码
- 将一个文件作为下载的形式打开【下载文件】,添加报文头context.Response.AddHeader("Content-disposition", "attachment; filename="
- 文件下载:"Content-disposition","attachment; filename=中文名>>>解决方案
- Response.setHeader("Content-Disposition", "attachment; filename=" + fileName+".xls");file.Name为中文则乱码
- 使用response.setHeader("Content-Disposition","attachment;filename="+fName)下载文件,中文文件名无法显示的问题
- 文件下载:"Content-disposition","attachment; filename=中文名>>>解决方案