CookieContainer.Add CookieContainer.Add CookieContainer.Add CookieContainer.Add Method

定義

Cookie 加入至 CookieContainerAdds a Cookie to a CookieContainer.

多載

Add(Cookie) Add(Cookie) Add(Cookie)

Cookie 加入至 CookieContainerAdds a Cookie to a CookieContainer. 這個方法使用 Cookie 中的網域以決定要與 Cookie 關聯的網域集合。This method uses the domain from the Cookie to determine which domain collection to associate the Cookie with.

Add(CookieCollection) Add(CookieCollection) Add(CookieCollection) Add(CookieCollection)

CookieCollection 的內容加入 CookieContainerAdds the contents of a CookieCollection to the CookieContainer.

Add(Uri, Cookie) Add(Uri, Cookie) Add(Uri, Cookie)

Cookie 加入至特定 URI 的 CookieContainerAdds a Cookie to the CookieContainer for a particular URI.

Add(Uri, CookieCollection) Add(Uri, CookieCollection) Add(Uri, CookieCollection)

CookieCollection 的內容加入至特定 URI 的 CookieContainerAdds the contents of a CookieCollection to the CookieContainer for a particular URI.

Cookie 加入至 CookieContainerAdds a Cookie to a CookieContainer. 這個方法使用 Cookie 中的網域以決定要與 Cookie 關聯的網域集合。This method uses the domain from the Cookie to determine which domain collection to associate the Cookie with.

public:
 void Add(System::Net::Cookie ^ cookie);
public void Add (System.Net.Cookie cookie);
member this.Add : System.Net.Cookie -> unit

參數

cookie
Cookie Cookie Cookie Cookie

要加入至 CookieCookieContainerThe Cookie to be added to the CookieContainer.

例外狀況

cookie 的網域為 null 或空字串 ("")。The domain for cookie is null or the empty string ("").

cookie 大於 maxCookieSizecookie is larger than maxCookieSize.

-或--or- cookie 的網域不是有效的 URI。the domain for cookie is not a valid URI.

備註

如果屬性等於或Capacity超過屬性,則cookie會先從容器Cookie中移除一或多個實例,然後再新增參數。 CountIf the Count property equals or exceeds the Capacity property, one or more Cookie instances are removed from the container before adding the cookie parameter. Cookie移除Count 足夠的實例,如下所示:如果指定範圍內有過期的實例,則會清除它們。CapacityEnough Cookie instances are removed to bring Count below Capacity as follows: if there are expired instances in the given scope, they are cleaned up. 如果沒有,則會找到最近使用CookieCollection的最少,並從容器中移除。If not, then the least recently used CookieCollection is found and removed from the container.

另請參閱

Add(CookieCollection) Add(CookieCollection) Add(CookieCollection) Add(CookieCollection)

CookieCollection 的內容加入 CookieContainerAdds the contents of a CookieCollection to the CookieContainer.

public:
 void Add(System::Net::CookieCollection ^ cookies);
public void Add (System.Net.CookieCollection cookies);
member this.Add : System.Net.CookieCollection -> unit
Public Sub Add (cookies As CookieCollection)

參數

例外狀況

備註

如果屬性等於屬性,則會先從容器Cookie中移除一或多個實例,再新增cookies參數的內容。 Capacity CountIf the Count property equals the Capacity property, one or more Cookie instances are removed from the container before adding the contents of the cookies parameter. Cookie移除足夠的實例來騰出空間cookies ,如下所示:如果有過期的實例,則會清除它們。Enough Cookie instances are removed to make room for cookies as follows: if there are expired instances, they are cleaned up. 如果不是,或如果需要更多空間,則會找到最近CookieCollection使用的最少,並從容器中移除。If not, or if more room is needed, then the least recently used CookieCollection is found and removed from the container.

另請參閱

Cookie 加入至特定 URI 的 CookieContainerAdds a Cookie to the CookieContainer for a particular URI.

public:
 void Add(Uri ^ uri, System::Net::Cookie ^ cookie);
public void Add (Uri uri, System.Net.Cookie cookie);
member this.Add : Uri * System.Net.Cookie -> unit

參數

uri
Uri Uri Uri Uri

要加入至 CookieCookieContainer 的 URI。The URI of the Cookie to be added to the CookieContainer.

cookie
Cookie Cookie Cookie Cookie

要加入至 CookieCookieContainerThe Cookie to be added to the CookieContainer.

例外狀況

urinull,或 cookienulluri is null or cookie is null.

cookie 大於 maxCookieSizecookie is larger than maxCookieSize.

-或--or- cookie 的網域不是有效的 URI。The domain for cookie is not a valid URI.

備註

如果您只針對Cookie一個特定主控制項加入實例,請勿Domain設定Cookie實例的屬性。If you add a Cookie instance for just one specific host, do not set the Domain property of the Cookie instance. 這會根據 URI 自動設定。This is set automatically, based on the URI.

如果您的 URI 對應至您的本機網域,並將其傳送至本機網域上的所有Cookie主機,請將Domain屬性設定為等於 "local"。If your URI corresponds to your local domain and sends to all the hosts on the local domain, set the CookieDomain property equal to ".local". 否則,請確定它符合 URI 中使用的主機名稱。Otherwise, make sure it matches the host name used in the URI.

如果的Version屬性Cookie是 Netscape Path ,則的屬性(如果未明確設定)是衍生自uri,而則是來自uri的完整路徑,包括頁面名稱。CookieIf the Version property of a Cookie is Netscape, the Path property of the Cookie, if not set explicitly, is derived from the URI and is the complete path from the URI, including the page name.

如果屬性等於屬性, Cookiecookie會先從容器中移除一或多個實例,然後再新增參數。 Capacity CountIf the Count property equals the Capacity property, one or more Cookie instances are removed from the container before adding the cookie parameter. Cookie移除Count 足夠的實例,如下所示:如果範圍內有過期的實例,則會清除它們。CapacityEnough Cookie instances are removed to bring Count below Capacity as follows: if there are expired instances in scope, they are cleaned up. 如果沒有,則會找到最近使用CookieCollection的最少,並從容器中移除。If not, then the least recently used CookieCollection is found and removed from the container.

另請參閱

Add(Uri, CookieCollection) Add(Uri, CookieCollection) Add(Uri, CookieCollection)

CookieCollection 的內容加入至特定 URI 的 CookieContainerAdds the contents of a CookieCollection to the CookieContainer for a particular URI.

public:
 void Add(Uri ^ uri, System::Net::CookieCollection ^ cookies);
public void Add (Uri uri, System.Net.CookieCollection cookies);
member this.Add : Uri * System.Net.CookieCollection -> unit

參數

uri
Uri Uri Uri Uri

要加入至 CookieCollectionCookieContainer 的 URI。The URI of the CookieCollection to be added to the CookieContainer.

例外狀況

cookies 內其中一個 Cookie 的網域是 nullThe domain for one of the cookies in cookies is null.

cookies 內其中一個 Cookie 包含無效的網域。One of the cookies in cookies contains an invalid domain.

備註

如果您只針對Cookie一個特定主控制項加入實例,請勿Domain設定Cookie實例的屬性。If you add a Cookie instance for just one specific host, do not set the Domain property of the Cookie instance. 這會根據 URI 自動設定。This is set automatically, based on the URI.

如果您的 URI 對應至您的本機網域,並將其傳送至本機網域上的所有Cookie主機,請將Domain屬性設定為等於 "local"。If your URI corresponds to your local domain and sends to all the hosts on the local domain, set the CookieDomain property equal to ".local". 否則,請確定它符合 URI 中使用的主機名稱。Otherwise, make sure it matches the host name used in the URI.

如果Count Cookie等於Capacitycookie則會先從容器中移除一或多個實例,然後再新增參數。If Count equals Capacity, one or more Cookie instances is removed from the container before adding the cookie parameter. Cookie移除足夠的實例CountCapacity如下所示:如果範圍中有過期的實例,則會清除它們。Enough Cookie instances are removed to bring Count below Capacity as follows: if there are expired instances in scope they are cleaned up. 如果沒有,則會找到最近使用CookieCollection的最少,並從容器中移除。If not, then the least recently used CookieCollection is found and removed from the container.

另請參閱

適用於