HttpCookieCollection.Set(HttpCookie) 方法

定义

更新 Cookie 集合中现有 Cookie 的值。Updates the value of an existing cookie in a cookie collection.

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

参数

cookie
HttpCookie

要更新的 HttpCookie 对象。The HttpCookie object to update.

示例

下面的示例更新现有 cookie 的值。The following example updates the value of an existing cookie.

MyCookie.Value = DateTime.Now.ToString();
 MyCookieCollection.Set(MyCookie);

MyCookie.Value = DateTime.Now().ToString()
 MyCookieCollection.Set(MyCookie)
    

注解

Set方法首先检查 cookie 是否已存在于集合中,如果是,则更新它。The Set method first checks to see if a cookie already exists in the collection and if so updates it. Set 方法不允许 cookie 集合中存在重复的 cookie。The Set method does not allow duplicate cookies in the cookie collection. 若要在 cookie 集合中添加重复 cookie,请使用 Add 方法。To add duplicate cookies in the cookie collection, use the Add method.

适用于

另请参阅