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
public static void SetCookie (
	Uri uri, 
	String value
public static function SetCookie (
	uri : Uri, 
	value : String
You cannot use methods in XAML.



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


The String that contains the cookie data.

Exception typeCondition


Application is hosted inside an HTMLIFrame.


A Win32 error is raised by InternetSetCookie (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 or across application sessions.

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


When this is passed to SetCookie, along with the Uri of the location for which the cookie should be set, a cookie is created in-memory, and is only available to the process that created it.

To store a cookie across application sessions, an expiration date must be added to the cookie, using the following format:


A cookie with an expiration date is stored in the current Windows installation's temporary internet files folder until the cookie expires.

See Application Cookies Sample for an example of creating and retrieving cookies.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions