FormsAuthenticationEventHandler Delegar

Definição

Representa o método que manipula o evento FormsAuthentication_OnAuthenticate de um FormsAuthenticationModule.Represents the method that handles the FormsAuthentication_OnAuthenticate event of a FormsAuthenticationModule.

public delegate void FormsAuthenticationEventHandler(System::Object ^ sender, FormsAuthenticationEventArgs ^ e);
public delegate void FormsAuthenticationEventHandler(object sender, FormsAuthenticationEventArgs e);
type FormsAuthenticationEventHandler = delegate of obj * FormsAuthenticationEventArgs -> unit
Public Delegate Sub FormsAuthenticationEventHandler(sender As Object, e As FormsAuthenticationEventArgs)

Parâmetros

sender
Object

A fonte do evento.The source of the event.

e
FormsAuthenticationEventArgs

Um FormsAuthenticationEventArgs que contém os dados do evento.A FormsAuthenticationEventArgs that contains the event data.

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 com um personalizado Identity .The following code example uses the FormsAuthentication_OnAuthenticate event to set the User property of the current HttpContext to a GenericPrincipal object with a custom 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 FormsAuthenticationEventHandler delegado é definido para o Authenticate evento da FormsAuthenticationModule classe.The FormsAuthenticationEventHandler delegate is defined for the Authenticate event of the FormsAuthenticationModule class. Você pode acessar o Authenticate evento da FormsAuthenticationModule classe especificando uma sub-rotina chamada FormsAuthentication_OnAuthenticate no arquivo global. asax para seu aplicativo ASP.net.You can access the Authenticate event of the FormsAuthenticationModule class by specifying a subroutine named FormsAuthentication_OnAuthenticate in the Global.asax file for your ASP.NET application. O Authenticate evento é gerado durante o AuthenticateRequest evento.The Authenticate event is raised during the AuthenticateRequest event.

O FormsAuthenticationModule constrói um FormsAuthenticationEventArgs objeto usando o atual HttpContext e o passa para o evento FormsAuthentication_OnAuthenticate .The FormsAuthenticationModule constructs a FormsAuthenticationEventArgs object using the current HttpContext and passes it to the FormsAuthentication_OnAuthenticate event.

Você pode usar a User Propriedade do FormsAuthenticationEventArgs objeto fornecido ao evento FormsAuthentication_OnAuthenticate para definir a User Propriedade do atual HttpContext como um IPrincipal objeto personalizado.You can use the User property of the FormsAuthenticationEventArgs object supplied to the FormsAuthentication_OnAuthenticate event to set the User property of the current HttpContext to a custom IPrincipal object. 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 na URL será usada.If you do not specify a value for the User property during the FormsAuthentication_OnAuthenticate event, the identity supplied by the forms authentication ticket in the cookie or URL is used.

O evento FormsAuthentication_OnAuthenticate só é gerado quando a autenticação Mode é definida como Forms e o FormsAuthenticationModule é um módulo http ativo para o aplicativo.The FormsAuthentication_OnAuthenticate event is only raised when the authentication Mode is set to Forms and the FormsAuthenticationModule is an active HTTP module for the application.

Métodos de Extensão

GetMethodInfo(Delegate)

Obtém um objeto que representa o método representado pelo delegado especificado.Gets an object that represents the method represented by the specified delegate.

Aplica-se a