CreatingCookieEventArgs Class
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides data for the CreatingCookie event.
public ref class CreatingCookieEventArgs : EventArgs
public class CreatingCookieEventArgs : EventArgs
type CreatingCookieEventArgs = class
inherit EventArgs
Public Class CreatingCookieEventArgs
Inherits EventArgs
- Inheritance
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
FormsAuthenticationTicket
(1,
e.UserName,
DateTime.Now,
DateTime.Now.AddMinutes(30),
e.IsPersistent,
e.CustomCredential,
FormsAuthentication.FormsCookiePath);
string encryptedTicket =
FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie
(FormsAuthentication.FormsCookieName,
encryptedTicket);
cookie.Expires = DateTime.Now.AddMinutes(30);
HttpContext.Current.Response.Cookies.Add(cookie);
e.CookieIsSet = true;
}
Sub AuthenticationService_CreatingCookie(ByVal sender As Object, _
ByVal e As System.Web.ApplicationServices.CreatingCookieEventArgs)
Dim ticket As FormsAuthenticationTicket = New _
FormsAuthenticationTicket _
(1, _
e.Username, _
DateTime.Now, _
DateTime.Now.AddMinutes(30), _
e.IsPersistent, _
e.CustomCredential, _
FormsAuthentication.FormsCookiePath)
Dim encryptedTicket As String = FormsAuthentication.Encrypt(ticket)
Dim cookie As HttpCookie = New _
HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
cookie.Expires = DateTime.Now.AddMinutes(30)
HttpContext.Current.Response.Cookies.Add(cookie)
e.CookieIsSet = True
End Sub
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 UserNamePassword, 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.
Cookie |
Gets or sets a value that indicates whether the authentication cookie has been created. |
Custom |
Gets additional authentication values that are provided by the user. |
Is |
Gets a value that indicates whether the authentication cookie should be retained beyond the current session. |
Password |
Gets the password for the user. |
User |
Gets the name for the user. |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Get |
Serves as the default hash function. (Inherited from Object) |
Get |
Gets the Type of the current instance. (Inherited from Object) |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
To |
Returns a string that represents the current object. (Inherited from Object) |
Product | Versions |
---|---|
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: