我发现以下 asp.net 代码在从数据库提供文件时非常有用:
Response.AppendHeader("content-disposition", "attachment; filename=" + fileName);
这让用户可以将文件保存到他们的计算机上,然后决定如何使用它,而不是浏览器尝试使用该文件。
content-disposition 响应头还能做些什么?
最佳答案
请注意 RFC 6266取代下面引用的 RFC。 Section 7概述了一些相关的安全问题。
content-disposition 头的权限是RFC 1806和 RFC 2183.人们还设计了content-disposition hacking.请务必注意,content-disposition header 不是 HTTP 1.1 标准的一部分。
HTTP 1.1 标准 ( RFC 2616 ) 还提到了内容处置可能带来的安全副作用:
15.5 Content-Disposition Issues
RFC 1806 [35], from which the often implemented Content-Disposition
(see section 19.5.1) header in HTTP is derived, has a number of very
serious security considerations. Content-Disposition is not part of
the HTTP standard, but since it is widely implemented, we are
documenting its use and risks for implementors. See RFC 2183 [49]
(which updates RFC 1806) for details.
关于http - 在 HTTP 响应 header 中使用 content-disposition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1012437/