FormsAuthenticationModule.Authenticate Evento

Definição

Ocorre quando o aplicativo autentica a solicitação atual.

public:
 event System::Web::Security::FormsAuthenticationEventHandler ^ Authenticate;
public event System.Web.Security.FormsAuthenticationEventHandler Authenticate;
member this.Authenticate : System.Web.Security.FormsAuthenticationEventHandler 
Public Custom Event Authenticate As FormsAuthenticationEventHandler 

Tipo de evento

Exemplos

O exemplo de código a seguir usa o evento FormsAuthentication_OnAuthenticate para definir a User propriedade do atual HttpContext como um GenericPrincipal objeto que tem um personalizado Identity.

public void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args)
{
  if (FormsAuthentication.CookiesSupported)
  {
    if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
    {
      try
      {
        FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(
          Request.Cookies[FormsAuthentication.FormsCookieName].Value);
        
        args.User = new System.Security.Principal.GenericPrincipal(
          new Samples.AspNet.Security.MyFormsIdentity(ticket),
          new string[0]);
      }
      catch (Exception e)
      {
        // Decrypt method failed.
      }
    }
  }
  else
  {
    throw new HttpException("Cookieless Forms Authentication is not " +
                            "supported for this application.");
  }
}
Public Sub FormsAuthentication_OnAuthenticate(sender As Object, _
                                              args As FormsAuthenticationEventArgs)
  If FormsAuthentication.CookiesSupported Then
    If Not Request.Cookies(FormsAuthentication.FormsCookieName) Is Nothing Then
      Try
        Dim ticket As FormsAuthenticationTicket = FormsAuthentication.Decrypt( _
          Request.Cookies(FormsAuthentication.FormsCookieName).Value)
        
        args.User = New System.Security.Principal.GenericPrincipal( _
          New Samples.AspNet.Security.MyFormsIdentity(ticket), _
          New String(0) {})
      Catch e As HttpException
        ' Decrypt method failed.
      End Try
    End If
  Else
      Throw New Exception("Cookieless Forms Authentication is not " & _
                            "supported for this application.")
  End If
End Sub

Comentários

O Authenticate evento é gerado durante o AuthenticateRequest evento.

Você pode manipular o Authenticate evento da FormsAuthenticationModule classe especificando uma sub-rotina chamada FormsAuthentication_OnAuthenticate no arquivo Global.asax para seu aplicativo ASP.NET.

Você pode usar a FormsAuthenticationEventArgsUser propriedade fornecida ao evento FormsAuthentication_OnAuthenticate para definir a User propriedade do atual HttpContext como um objeto personalizado IPrincipal . Se você não especificar um valor para a User propriedade durante o evento FormsAuthentication_OnAuthenticate , a identidade fornecida pelo tíquete de autenticação de formulários no cookie ou url será usada.

O evento FormsAuthentication_OnAuthenticate só é gerado quando o modo de autenticação é definido Forms como no elemento Elemento de autenticação (ASP.NET Esquema de Configurações) do arquivo de configuração do aplicativo e o FormsAuthenticationModule é um módulo HTTP ativo para o aplicativo.

Aplica-se a

Confira também