Cookie Class
Provides an object for use with HTTP requests to persist state information for a Silverlight-based application.
Namespace: System.Net
Assembly: System.Net (in System.Net.dll)
The Cookie type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() | Cookie() | Initializes a new instance of the Cookie class. |
![]() ![]() | Cookie(String, String) | Initializes a new instance of the Cookie class with the specified name and value. |
![]() ![]() | Cookie(String, String, String) | Initializes a new instance of the Cookie class with the specified name, value and path. |
![]() ![]() | Cookie(String, String, String, String) | Initializes a new instance of the Cookie class with the specified name, value, path and domain. |
| Name | Description | |
|---|---|---|
![]() ![]() | Comment | Gets or sets an optional comment that provides the intended use of the cookie. |
![]() ![]() | CommentUri | Gets or sets a Uniform Resource Identifier (URI) comment that the server provides for this Cookie. |
![]() ![]() | Discard | Gets or sets a values that indicates whether the client is to discard the Cookie at the end of the current session. |
![]() ![]() | Domain | Gets or sets the domain of a Uniform Resource Identifier (URI) for which the cookie is valid. |
![]() ![]() | Expired | Gets or sets a values that indicates whether this Cookie is no longer valid. |
![]() ![]() | Expires | Gets or sets the expiration date and time for the Cookie. |
![]() ![]() | HttpOnly | Gets or sets a value that indicates whether a page script or other active content can access this cookie. |
![]() ![]() | Name | Gets or sets the name of this cookie. |
![]() ![]() | Path | Gets or sets the path portion of a Uniform Resource Identifier (URI) to which this cookie applies. |
![]() ![]() | Port | Gets or sets a list of Transmission Control Protocol (TCP) ports to which this cookie applies. |
![]() ![]() | Secure | Gets or sets a value that indicates whether including the cookie on subsequent client requests requires the request be sent with Secure Hypertext Transport Protocol (HTTPS). |
![]() ![]() | TimeStamp | Gets the date and time that this Cookie was created. |
![]() ![]() | Value | Gets or sets the value of the Cookie. |
![]() ![]() | Version | Gets or sets a single digit that indicates the version of HTTP state maintenance to which the cookie conforms. |
| Name | Description | |
|---|---|---|
![]() ![]() | Equals | Determines if two Cookie objects are equal. (Overrides Object::Equals(Object).) |
![]() ![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) |
![]() ![]() | GetHashCode | Gets the hash code for this Cookie. (Overrides Object::GetHashCode().) |
![]() ![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() ![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() ![]() | ToString | Returns a string representation of the Cookie suitable for including in an HTTP cookie request. (Overrides Object::ToString().) |
The Cookie class is used by a client application to retrieve information about cookies that are received with HTTP responses. The following cookie formats are supported during parsing of the HTTP response headers: the original Netscape specification, RFC 2109, and RFC 2965.
Cookies are stored in a CookieContainer on a Web request, and a CookieCollection on a Web response. You must always create a CookieContainer to send with a request if you want cookies to be returned on the response. This is also true for HTTPOnly cookies, which you cannot retrieve.
The following example shows how to add cookies to a request and retrieve them from a response.
<UserControl x:Class="CookiesEx.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"> <StackPanel x:Name="LayoutRoot"> <Button Width="200" Height="50" Content="Click to send request" HorizontalAlignment="Left" x:Name="button1" Click="button1_Click" Margin="5"/> <TextBlock Margin="5" Width="600" Height="400" x:Name="tb1" HorizontalAlignment="Left" /> </StackPanel> </UserControl>
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
