HttpResponse.AppendCookie(HttpCookie) HttpResponse.AppendCookie(HttpCookie) HttpResponse.AppendCookie(HttpCookie) HttpResponse.AppendCookie(HttpCookie) Method

定义

将一个 HTTP Cookie 添加到内部 Cookie 集合。Adds an HTTP cookie to the intrinsic cookie collection.

public:
 void AppendCookie(System::Web::HttpCookie ^ cookie);
public void AppendCookie (System.Web.HttpCookie cookie);
member this.AppendCookie : System.Web.HttpCookie -> unit
Public Sub AppendCookie (cookie As HttpCookie)

参数

cookie
HttpCookie HttpCookie HttpCookie HttpCookie

要添加到输出流的 HttpCookieThe HttpCookie to add to the output stream.

异常

在发送了 HTTP 标头之后会追加一个 Cookie。A cookie is appended after the HTTP headers have been sent.

示例

下面的示例创建一个名为LastVisit的新 cookie,将该 cookie 的值设置为当前日期和时间,并将该 cookie 追加到当前 cookie 集合中。The following example creates a new cookie named LastVisit, sets the value of the cookie to the current date and time, and appends the cookie to the current cookie collection. Cookie 集合中的所有 cookie 都通过 HTTP 输出流发送到Set-Cookie标头中的客户端。All cookies in the cookie collection are sent to the client in the Set-Cookie header with the HTTP output stream.

HttpCookie MyCookie = new HttpCookie("LastVisit");
 MyCookie.Value = DateTime.Now.ToString();
 Response.AppendCookie(MyCookie);
    
Dim MyCookie As New HttpCookie("LastVisit")
 MyCookie.Value = CStr(DateTime.Now())
 Response.AppendCookie(MyCookie)
    

适用于