CookieContainer 類別

定義

提供 CookieCollection 物件集合的容器 (Container)。Provides a container for a collection of CookieCollection objects.

public ref class CookieContainer
[System.Serializable]
public class CookieContainer
type CookieContainer = class
Public Class CookieContainer
繼承
CookieContainer
屬性

備註

是一種資料結構,可提供Cookie類別實例的儲存區,並以類似資料庫的方式存取。 CookieContainerA CookieContainer is a data structure that provides storage for instances of the Cookie class, and which is accessed in a database-like manner. CookieContainer具有容量限制,會在容器由屬性建立或變更時設定。The CookieContainer has a capacity limit that is set when the container is created or changed by a property.

Cookie類別的實例會根據其原始 URI 新增至容器。An instance of the Cookie class is added to the container based on its originating URI. 它會加入至與 URI CookieCollection相關聯的內部。It is added to an internal CookieCollection associated with the URI. 會以 URI CookieCollection作為基礎,從容器中抓取,或當做可用於提交 HTTP WebRequests 的字串。 CookieA Cookie is retrieved from the container based on the URI as a CookieCollection, or as a string that can be used to submit HTTP WebRequests.

有三個屬性,可控制容器內容的數量: CapacityMaxCookieSizePerDomainCapacityCookieContainerThe CookieContainer has three properties that govern the volume of the content of the container: Capacity, MaxCookieSize, and PerDomainCapacity. 這些值分別具有300、4096和20的預設設定。These values have the default settings of 300, 4096, and 20 respectively. 當新增至容器時,會使用這些屬性來判斷Cookie是否CookieContainer應該捨棄已包含在中的,以騰出空間給新的。 CookieWhen a Cookie is added to the container, these properties are used to determine whether a Cookie already contained in the CookieContainer should be discarded to make room for the new one. 會持續追蹤每個新增,以確保Capacity PerDomainCapacity不會超過限制。 CookieContainerThe CookieContainer keeps track of each addition to ensure that neither the Capacity nor the PerDomainCapacity limits are exceeded. 如果超過一個或兩者, Cookie則會移除所持有的CookieContainer實例。If one or both are exceeded, then Cookie instances held by the CookieContainer are removed. 首先,會移除Cookie任何已過期的。First, any expired Cookie is removed. 如果必須重新擷取進一步的容量,則會清除最近使用CookieCollection的最少。If further capacity must be recaptured, then the least-recently used CookieCollection is purged.

建構函式

CookieContainer()

初始化 CookieContainer 類別的新執行個體。Initializes a new instance of the CookieContainer class.

CookieContainer(Int32)

以容器可以保留之 CookieContainer 執行個體數目的指定值,初始化 Cookie 類別的新執行個體。Initializes a new instance of the CookieContainer class with a specified value for the number of Cookie instances that the container can hold.

CookieContainer(Int32, Int32, Int32)

以特定屬性初始化 CookieContainer 類別的新執行個體。Initializes a new instance of the CookieContainer class with specific properties.

欄位

DefaultCookieLengthLimit

以位元組為單位表示 Cookie 可以保留之 CookieContainer 執行個體的預設大小最大值。Represents the default maximum size, in bytes, of the Cookie instances that the CookieContainer can hold. 這個欄位是常數。This field is constant.

DefaultCookieLimit

表示 Cookie 可以保留之 CookieContainer 執行個體的預設最大數目。Represents the default maximum number of Cookie instances that the CookieContainer can hold. 這個欄位是常數。This field is constant.

DefaultPerDomainCookieLimit

表示 Cookie 在每一個網域可以參考之 CookieContainer 執行個體的預設最大數目。Represents the default maximum number of Cookie instances that the CookieContainer can reference per domain. 這個欄位是常數。This field is constant.

屬性

Capacity

取得或設定 CookieContainer 可以保留的 Cookie 執行個體數目。Gets or sets the number of Cookie instances that a CookieContainer can hold.

Count

取得 Cookie 目前保留的 CookieContainer 執行個體數目。Gets the number of Cookie instances that a CookieContainer currently holds.

MaxCookieSize

表示 Cookie 允許的最大長度。Represents the maximum allowed length of a Cookie.

PerDomainCapacity

取得或設定 CookieContainer 在每一個網域可以保留的 Cookie 執行個體數目。Gets or sets the number of Cookie instances that a CookieContainer can hold per domain.

方法

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)

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

Add(Uri, Cookie)

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

Add(Uri, CookieCollection)

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

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetCookieHeader(Uri)

取得 HTTP Cookie 標頭,包含表示與特定 URI 關聯之 Cookie 執行個體的 HTTP Cookie。Gets the HTTP cookie header that contains the HTTP cookies that represent the Cookie instances that are associated with a specific URI.

GetCookies(Uri)

取得 CookieCollection,包含與特定 URI 關聯的 Cookie 執行個體。Gets a CookieCollection that contains the Cookie instances that are associated with a specific URI.

GetHashCode()

作為預設雜湊函數。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
SetCookies(Uri, String)

將 HTTP Cookie 標頭中一或多個 Cookie 的 Cookie 執行個體加入至特定 URI 的 CookieContainerAdds Cookie instances for one or more cookies from an HTTP cookie header to the CookieContainer for a specific URI.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於

另請參閱