CreatingCookieEventArgs Class

CreatingCookieEventArgs Class

Provides data for the CreatingCookie event.


Namespace:  System.Web.ApplicationServices
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public class CreatingCookieEventArgs : EventArgs

The CreatingCookieEventArgs type exposes the following members.

Public propertyCookieIsSetGets or sets a value that indicates whether the authentication cookie has been created.
Public propertyCustomCredentialGets additional authentication values that are provided by the user.
Public propertyIsPersistentGets a value that indicates whether the authentication cookie should be retained beyond the current session.
Public propertyPasswordGets the password for the user.
Public propertyUserNameGets the name for the user.

Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

The CreatingCookieEventArgs class supplies values to any CreatingCookie event handler. By using the properties of this class, you can retrieve user credentials when you create a custom authentication cookie.

The AuthenticationService class raises the CreatingCookie event when it sets the authentication cookie, after the user credentials have been authenticated. The AuthenticationService class constructs a CreatingCookieEventArgs object and passes it to any CreatingCookie event handler.

You retrieve the user credentials through the UserName Password, and CustomCredential properties. The CustomCredential property can contain any custom values that you need in order to authenticate, such as an identification number. The IsPersistent property indicates whether the authentication cookie should be retained past the current session. Set the CookieIsSet property to true if you create the authentication cookie, so that the AuthenticationService class does not create the cookie.

The following example shows an event handler for the CreatingCookie event. The handler retrieves user values from the CreatingCookieEventArgs object to customize the authentication cookie. The handler saves the value from the CustomCredential property in the authentication ticket and sets the CookieIsSet property to true to indicate that the authentication cookie has been created.

void AuthenticationService_CreatingCookie(object sender, 
    System.Web.ApplicationServices.CreatingCookieEventArgs e)
    FormsAuthenticationTicket ticket = new

    string encryptedTicket =

    HttpCookie cookie = new HttpCookie
    cookie.Expires = DateTime.Now.AddMinutes(30);

    e.CookieIsSet = true;

.NET Framework

Supported in: 4, 3.5

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

© 2016 Microsoft