什么时候使用Response.AddHeader?
发布于 2009-11-18 05:14:38
它用于向您的请求添加额外的HTTP Headers --如果您不熟悉HTTP头的用途,请阅读前面的链接。
大多数情况下,您最终会使用其他ASP.NET对象或方法(如Response.Cookies或Response.Redirect )间接设置标头。但是,在一些高级的、相对不常见的场景中,有时需要在代码中直接调用Response.AddHeader()。
例如,要在ASP.NET 3.5中引起HTTP301(永久)重定向,您需要使用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>发布于 2009-11-18 05:20:17
Justin Grant的答案的一个例子是,如果你想输出excel,你可以这样做:
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("content-disposition", "attachment;filename=test.xls");https://stackoverflow.com/questions/1751820
复制相似问题