CreatingCookieEventArgs.CustomCredential Propriedade

Definição

Obtém valores de autenticação adicionais que são fornecidos pelo usuário.Gets additional authentication values that are provided by the user.

public:
 property System::String ^ CustomCredential { System::String ^ get(); };
public string CustomCredential { get; }
member this.CustomCredential : string
Public ReadOnly Property CustomCredential As String

Valor da propriedade

String

Os valores personalizados necessários para a autenticação, além de nome de usuário e senha.The custom values required for authentication, other than user name and password.

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 in order to customize the authentication cookie. O valor passado na CustomCredential propriedade é armazenado na UserData Propriedade do tíquete de autenticação de formulários.The value passed in the CustomCredential property is stored in the UserData property of the forms authentication ticket.

Observação

Armazene a CustomCredential propriedade em um cookie somente quando souber que os dados na propriedade não são confidenciais.Store the CustomCredential property in a cookie only when you know that the data in the property is not sensitive. Usuários mal-intencionados podem acessar os valores no cookie.Malicious users can access the values in the cookie.

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

Você usa a CustomCredential propriedade para recuperar valores personalizados no tíquete de autenticação.You use the CustomCredential property to retrieve custom values in the authentication ticket. A CustomCredential propriedade contém o valor passado para o Login método.The CustomCredential property contains the value passed to the Login method. Normalmente, essa propriedade é usada para passar valores personalizados que devem ser validados com o nome de usuário e a senha, como um número de identificação.Typically, this property is used to pass custom values that must be validated with the user name and password, such as an identification number. Se mais de um valor for armazenado na propriedade, você deverá analisar a CustomCredential propriedade para recuperar valores.If more than one value is stored in the property, you must parse the CustomCredential property in order to retrieve values.

Aplica-se a