PDF处理程序:内容处理文件名

use*_*308 16 filenames ashx handler content-disposition save-as

我正在Web浏览器(IE8)中输出PDF文件,HttpContext.Response.writefile(fileName)效果很好.当我尝试保存文件时,它会给我一个默认的ashx处理程序的名称.我想实际传递真实姓名.

我尝试添加标题信息如下:

context.Response.AddHeader("content-disposition", "attachment; filename=" + fileInfo.Name);
Run Code Online (Sandbox Code Playgroud)

它可以工作,但我不希望用户必须在打开和保存之间进行选择,我希望文件正常打开,如果用户选择保存它,那么对话框将为他/她提供默认文件名.

我也尝试过:

context.Response.AddHeader("content-disposition", "inline; filename=" + fileInfo.Name);
Run Code Online (Sandbox Code Playgroud)

或者就像Scott Hanselman在博客中提到的那样.

context.Response.AddHeader("content-disposition", "filename=" + fileInfo.Name);
Run Code Online (Sandbox Code Playgroud)

这些都不适合我.有人有什么想法吗?

Jul*_*hke 15

请参阅http://greenbytes.de/tech/tc2231/#inlwithasciifilenamepdf上的测试用例- 看起来这只是IE中缺少的功能.


zei*_*isi 5

我也遇到了这个问题。帮助我的还有将contenttype设置为application/pdf(而不是application/x-pdf已过时的)

response.setContentType("application/pdf");
response.setHeader("Content-disposition", "inline; filename=\"Report.pdf\"");
Run Code Online (Sandbox Code Playgroud)