# CookieCollection

Namespace: **Wisej.Base**

Assembly: **Wisej.Framework** (4.0.0.0)

Manages the collection of cookies for the current application.

{% tabs %}
{% tab title="C#" %}

```csharp
public class CookieCollection : IList<Cookie>, ICollection<Cookie>, IEnumerable<Cookie>, IEnumerable
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class CookieCollection
    Inherits IList(Of Cookie)
    Implements ICollection(Of Cookie), IEnumerable(Of Cookie), IEnumerable
```

{% endtab %}
{% endtabs %}

## Properties

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Count

[Int32](https://docs.microsoft.com/dotnet/api/system.int32): Returns the number of [Cookie](https://docs.wisej.com/api/wisej.base/general/cookie) items in the collection.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Item(name)

[String](https://docs.microsoft.com/dotnet/api/system.string): Returns the [Cookie](https://docs.wisej.com/api/wisej.base/general/cookie) with a specific name from a [CookieCollection](https://docs.wisej.com/api/wisej.base/general/wisej.base.cookiecollection).

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*name* is null.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Item(index)

[Cookie](https://docs.wisej.com/api/wisej.base/general/cookie): Returns the [Cookie](https://docs.wisej.com/api/wisej.base/general/cookie) with a specific name from a [CookieCollection](https://docs.wisej.com/api/wisej.base/general/wisej.base.cookiecollection).

**Throws:**

* [IndexOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.indexoutofrangeexception)*index* is out of range.

## Methods

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Add(cookie)

Adds a cookie to the collection.

| Parameter  | Type                                                           | Description        |
| ---------- | -------------------------------------------------------------- | ------------------ |
| **cookie** | [Cookie](https://docs.wisej.com/api/wisej.base/general/cookie) | The cookie to add. |

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Add(name, value)

Adds a new cookie to the collection.

| Parameter | Type                                                          | Description                            |
| --------- | ------------------------------------------------------------- | -------------------------------------- |
| **name**  | [String](https://docs.microsoft.com/dotnet/api/system.string) | The case-sensitive name of the cookie. |
| **value** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The value of the new cookie to add.    |

**Returns:** [Cookie](https://docs.wisej.com/api/wisej.base/general/cookie).

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Add(name, value, domain)

Adds a new cookie to the collection.

| Parameter  | Type                                                          | Description                                                |
| ---------- | ------------------------------------------------------------- | ---------------------------------------------------------- |
| **name**   | [String](https://docs.microsoft.com/dotnet/api/system.string) | The case-sensitive name of the cookie.                     |
| **value**  | [String](https://docs.microsoft.com/dotnet/api/system.string) | The value of the new cookie to add.                        |
| **domain** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The domain, or partial domain, associated with the cookie. |

**Returns:** [Cookie](https://docs.wisej.com/api/wisej.base/general/cookie).

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Add(name, value, expires)

Adds a new cookie to the collection.

| Parameter   | Type                                                              | Description                                 |
| ----------- | ----------------------------------------------------------------- | ------------------------------------------- |
| **name**    | [String](https://docs.microsoft.com/dotnet/api/system.string)     | The case-sensitive name of the cookie.      |
| **value**   | [String](https://docs.microsoft.com/dotnet/api/system.string)     | The value of the new cookie.                |
| **expires** | [DateTime](https://docs.microsoft.com/dotnet/api/system.datetime) | The expiration date/time of the new cookie. |

**Returns:** [Cookie](https://docs.wisej.com/api/wisej.base/general/cookie).

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Add(name, value, domain, expires)

Adds a new cookie to the collection.

| Parameter   | Type                                                              | Description                                 |
| ----------- | ----------------------------------------------------------------- | ------------------------------------------- |
| **name**    | [String](https://docs.microsoft.com/dotnet/api/system.string)     | The case-sensitive name of the cookie.      |
| **value**   | [String](https://docs.microsoft.com/dotnet/api/system.string)     | The value of the new cookie.                |
| **domain**  | [String](https://docs.microsoft.com/dotnet/api/system.string)     | The value of the new cookie.                |
| **expires** | [DateTime](https://docs.microsoft.com/dotnet/api/system.datetime) | The expiration date/time of the new cookie. |

**Returns:** [Cookie](https://docs.wisej.com/api/wisej.base/general/cookie).

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Clear()

Delete all cookies from the collection. NOTE: Cookies are only removed from the collection, not from the client. You need to set the expiration date to remove it from the client.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Contains(cookie)

Determines whether the cookie is present in the collection.

| Parameter  | Type                                                           | Description           |
| ---------- | -------------------------------------------------------------- | --------------------- |
| **cookie** | [Cookie](https://docs.wisej.com/api/wisej.base/general/cookie) | The cookie to locate. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean).

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) CopyTo(array, index)

Copies the cookie collection to a compatible one-dimensional array, starting at the specified index of the target array.

| Parameter | Type                                                               | Description                                                                      |
| --------- | ------------------------------------------------------------------ | -------------------------------------------------------------------------------- |
| **array** | [Cookie\[\]](https://docs.wisej.com/api/wisej.base/general/cookie) | The one-dimensional System.Array that is the destination of the elements copied. |
| **index** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)        | The zero-based index in array at which copying begins.                           |

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Get(name)

Returns the cookie with the specified name.

| Parameter | Type                                                          | Description                                      |
| --------- | ------------------------------------------------------------- | ------------------------------------------------ |
| **name**  | [String](https://docs.microsoft.com/dotnet/api/system.string) | The case-sensitive name of the cookie to locate. |

**Returns:** [Cookie](https://docs.wisej.com/api/wisej.base/general/cookie).

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) GetEnumerator()

**Returns:** [IEnumerator\<Cookie>](https://docs.microsoft.com/dotnet/api/system.collections.generic.ienumerator-1).

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) IndexOf(cookie)

Searches for the specified cookie and returns the zero-based index of the first occurrence.

| Parameter  | Type                                                           | Description           |
| ---------- | -------------------------------------------------------------- | --------------------- |
| **cookie** | [Cookie](https://docs.wisej.com/api/wisej.base/general/cookie) | The cookie to locate. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32).

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) IndexOf(name)

Searches for the specified cookie by name and returns the zero-based index of the first occurrence.

| Parameter | Type                                                          | Description                               |
| --------- | ------------------------------------------------------------- | ----------------------------------------- |
| **name**  | [String](https://docs.microsoft.com/dotnet/api/system.string) | The case-sensitive name cookie to locate. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32).

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Remove(cookie)

Removes the specified cookie from the collection. NOTE: Cookies are only removed from the collection, not from the client. You need to set the expiration date to remove it from the client.

| Parameter  | Type                                                           | Description                               |
| ---------- | -------------------------------------------------------------- | ----------------------------------------- |
| **cookie** | [Cookie](https://docs.wisej.com/api/wisej.base/general/cookie) | The cookie to remove from the collection. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if item is successfully removed; otherwise, false.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Remove(name)

Removes the specified cookie from the collection. NOTE: Cookies are only removed from the collection, not from the client. You need to set the expiration date to remove it from the client.

| Parameter | Type                                                          | Description                                                          |
| --------- | ------------------------------------------------------------- | -------------------------------------------------------------------- |
| **name**  | [String](https://docs.microsoft.com/dotnet/api/system.string) | The case-sensitive name of the cookie to remove from the collection. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if item is successfully removed; otherwise, false.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) RemoveAt(index)

Removes the cookie at the specified index. NOTE: Cookies are only removed from the collection, not from the client. You need to set the expiration date to remove it from the client.

| Parameter | Type                                                        | Description                                    |
| --------- | ----------------------------------------------------------- | ---------------------------------------------- |
| **index** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32) | The zero-based index of the element to remove. |
