Application::SetCookie Method

Creates a cookie for the location specified by a Uri.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)

public:
static void SetCookie(
	Uri^ uri, 
	String^ value
)

Parameters

uri
Type: System::Uri

The Uri that specifies the location for which the cookie should be created.

value
Type: System::String

The String that contains the cookie data.

ExceptionCondition
Win32Exception

A Win32 error is raised by the InternetSetCookie function (called by SetCookie) if a problem occurs when attempting to create the specified cookie.

A cookie is an arbitrary piece of data that can be stored by an application on the client machine during application sessions (session cookies) or across application sessions (persistent cookies). You can create both types of cookies by calling SetCookie.

Cookie data typically takes the form of a name/value pair in the following format:

Name=Value

You pass a string of this format to SetCookie, along with the Uri of the location for which the cookie should be set (typically, the application domain).

Whether a cookie is a session cookie or a persistent cookie depends on whether the cookie string that you pass to SetCookie includes an expiry date. The string for a session cookie does not include an expiry date. The string for a persistent cookie does, and must be in the following format:

NAME=VALUE; expires=DAY, DD-MMM-YYYY HH:MM:SS GMT

Persistent cookies are stored in the current Windows installation's Temporary Internet Files folder until they expire, in which case they are deleted. You can delete a persistent cookie from your application by setting its expiry date to a date/time value that is in the past.

For an overview of cookies in WPF, see Navigation Overview.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft