HttpResponse.AppendCookie(HttpCookie) 方法

定義

將 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

要加入至輸出資料流的 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)
    

適用於