CreatingCookieEventArgs Classe
Definição
Fornece dados para o evento de CreatingCookie .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
- Herança
Exemplos
O exemplo a seguir mostra um manipulador de eventos para o CreatingCookie evento.The following example shows an event handler for the CreatingCookie event. O manipulador recupera valores de usuário do CreatingCookieEventArgs objeto para personalizar o cookie de autenticação.The handler retrieves user values from the CreatingCookieEventArgs object to customize the authentication cookie. O manipulador salva o valor da CustomCredential propriedade no tíquete de autenticação e define a CookieIsSet propriedade como true para indicar que o cookie de autenticação foi criado.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
Comentários
A CreatingCookieEventArgs classe fornece valores para qualquer CreatingCookie manipulador de eventos.The CreatingCookieEventArgs class supplies values to any CreatingCookie event handler. Usando as propriedades dessa classe, você pode recuperar as credenciais do usuário ao criar um cookie de autenticação personalizado.By using the properties of this class, you can retrieve user credentials when you create a custom authentication cookie.
A AuthenticationService classe gera o CreatingCookie evento quando ele define o cookie de autenticação, depois que as credenciais do usuário são autenticadas.The AuthenticationService class raises the CreatingCookie event when it sets the authentication cookie, after the user credentials have been authenticated. A AuthenticationService classe constrói um CreatingCookieEventArgs objeto e o passa para qualquer CreatingCookie manipulador de eventos.The AuthenticationService class constructs a CreatingCookieEventArgs object and passes it to any CreatingCookie event handler.
Você recupera as credenciais do usuário nas UserName Password Propriedades e CustomCredential .You retrieve the user credentials through the UserNamePassword, and CustomCredential properties. A CustomCredential propriedade pode conter qualquer valor personalizado que você precise para autenticar, como um número de identificação.The CustomCredential property can contain any custom values that you need in order to authenticate, such as an identification number. A IsPersistent propriedade indica se o cookie de autenticação deve ser mantido após a sessão atual.The IsPersistent property indicates whether the authentication cookie should be retained past the current session. Defina a CookieIsSet propriedade como true se você criar o cookie de autenticação, para que a AuthenticationService classe não crie o cookie.Set the CookieIsSet property to true if you create the authentication cookie, so that the AuthenticationService class does not create the cookie.
Propriedades
| CookieIsSet |
Obtém ou define um valor que indica se o cookie de autenticação foi criado.Gets or sets a value that indicates whether the authentication cookie has been created. |
| CustomCredential |
Obtém valores de autenticação adicionais que são fornecidos pelo usuário.Gets additional authentication values that are provided by the user. |
| IsPersistent |
Obtém um valor que indica se o cookie de autenticação deve ser retido além da sessão atual.Gets a value that indicates whether the authentication cookie should be retained beyond the current session. |
| Password |
Obtém a senha do usuário.Gets the password for the user. |
| UserName |
Obtém o nome do usuário.Gets the name for the user. |
Métodos
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object. (Herdado de Object) |
| GetHashCode() |
Serve como a função de hash padrão.Serves as the default hash function. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Object) |