CreatingCookieEventArgs.CookieIsSet Propriedade

Definição

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.

public:
 property bool CookieIsSet { bool get(); void set(bool value); };
public bool CookieIsSet { get; set; }
member this.CookieIsSet : bool with get, set
Public Property CookieIsSet As Boolean

Valor da propriedade

Boolean

true Se o cookie de autenticação foi criado; caso contrário, false .true if the authentication cookie was created; otherwise, false.

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. A CookieIsSet propriedade é definida como true após a criação do tíquete de autenticação.The CookieIsSet property is set to true after the authentication ticket is 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 AuthenticationService classe verifica a CookieIsSet propriedade para determinar se o cookie de autenticação foi criado.The AuthenticationService class checks the CookieIsSet property to determine whether the authentication cookie has been created. Defina esse valor como true se você criar um cookie de autenticação em um manipulador de eventos para o CreatingCookie evento.You set this value to true if you create an authentication cookie in an event handler for the CreatingCookie event. Se CookieIsSet é definido como false (o valor padrão), a AuthenticationService classe cria um cookie de autenticação, isso substitui qualquer cookie que você tenha criado no manipulador para o CreatingCookie evento.If CookieIsSet is set to false (the default value), the AuthenticationService class creates an authentication cookie, This overwrites any cookie that you have created in the handler for the CreatingCookie event.

Aplica-se a