Page.Response 属性
获取与该 Page 对象关联的 HttpResponse 对象。该对象使您得以将 HTTP 响应数据发送到客户端,并包含有关该响应的信息。
命名空间: System.Web.UI
程序集: System.Web(在 System.Web.dll 中)
语法
C#
[BrowsableAttribute(false)]
public HttpResponse Response { get; }
属性值
类型:System.Web.HttpResponse当前与该页关联的 HttpResponse。
异常
异常 | 条件 |
HttpException | HttpResponse 对象不可用。 |
示例
下面的代码示例演示如何通过使用 HttpResponse 对象创建 Cookie,并将其添加到页的 HTTP 输出。
C#
HttpCookie MyCookie = new HttpCookie("LastVisit");
DateTime now = DateTime.Now;
MyCookie.Value = now.ToString();
MyCookie.Expires = now.AddHours(1);
Response.Cookies.Add(MyCookie);