-->

内容处置:内联在ASP.Net的PDF文件无法正常工作(Content-Disposition: i

2019-09-30 01:14发布

我试图PDF文件返回给浏览器标题Content-Dispostion:inline权,我创建这个文件之后。 浏览器的观众有问题,将其打开。

文件没有损坏。 如果我投入的浏览器,浏览器显示文件正确。 但我想创建文件,并在一个请求检查用户权限的文件。

这里是我的头和响应设置:

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline");
HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");
HttpContext.Current.Response.AddHeader("filename", $"objednavka-{OrderId}.pdf");
HttpContext.Current.Response.BinaryWrite(File.ReadAllBytes(filePath));
HttpContext.Current.Response.End();

火狐有错误的文件viewer.js,消息不确定,线1453。

在Firefox中的调试器响应网络是200 OK。

但在浏览器消息是连接丢失(所中断)。

Answer 1:

这两个建议帮助。 感谢大伙们。 这是怎么看起来正确的答案:

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("Content-Disposition", $"inline; filename=\"objednavka-{ OrderId}.pdf\"");
HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");
HttpContext.Current.Response.AddHeader("content-length", File.ReadAllBytes(filePath).Length.ToString());
HttpContext.Current.Response.BinaryWrite(File.ReadAllBytes(filePath));
HttpContext.Current.Response.End();


文章来源: Content-Disposition: inline for PDF file in ASP.Net not working