它用于为您的请求添加额外的HTTP标头 - 如果您不熟悉HTTP标头,请阅读上一个链接.
大多数情况下,您最终会使用其他ASP.NET对象或Response.Cookies或Response.Redirect等方法间接设置标头.但是,有一些高级的,相对不寻常的场景,有时需要在代码中直接调用Response.AddHeader().
例如,要在ASP.NET 3.5中导致HTTP 301(永久)重定向,您需要使用Response.AddHeader,使用如下代码:
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","/newpage.aspx");
}
</script>
Run Code Online (Sandbox Code Playgroud)