FormsAuthenticationEventHandler Gedelegeerde

Definitie

Vertegenwoordigt de methode die de FormsAuthentication_OnAuthenticate gebeurtenis van een 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)

Parameters

sender
Object

De bron van de gebeurtenis.

Voorbeelden

In het volgende codevoorbeeld wordt de gebeurtenis FormsAuthentication_OnAuthenticate gebruikt om de User eigenschap van de huidige HttpContext in te stellen op een GenericPrincipal object met een aangepast object 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

Opmerkingen

De FormsAuthenticationEventHandler gemachtigde wordt gedefinieerd voor de Authenticate gebeurtenis van de FormsAuthenticationModule klasse. U kunt de gebeurtenis Authenticate van de klasse FormsAuthenticationModule openen door een subroutine met de naam FormsAuthentication_OnAuthenticate op te geven in het bestand Global.asax voor uw ASP.NET toepassing. De Authenticate gebeurtenis wordt gegenereerd tijdens de AuthenticateRequest gebeurtenis.

Hiermee FormsAuthenticationModule wordt een FormsAuthenticationEventArgs object gemaakt met behulp van de huidige HttpContext en doorgegeven aan de FormsAuthentication_OnAuthenticate gebeurtenis.

U kunt de User eigenschap van het FormsAuthenticationEventArgs object dat is opgegeven aan de FormsAuthentication_OnAuthenticate gebeurtenis gebruiken om de User eigenschap van het huidige HttpContext in te stellen op een aangepast IPrincipal object. Als u tijdens de FormsAuthentication_OnAuthenticate gebeurtenis geen waarde voor de User eigenschap opgeeft, wordt de identiteit van het formulierverificatieticket in de cookie of URL gebruikt.

De FormsAuthentication_OnAuthenticate gebeurtenis wordt alleen gegenereerd wanneer de verificatie Mode is ingesteld op Forms en de FormsAuthenticationModule is een actieve HTTP-module voor de toepassing.

Extensiemethoden

Name Description
GetMethodInfo(Delegate)

Hiermee haalt u een object op dat de methode vertegenwoordigt die wordt vertegenwoordigd door de opgegeven gemachtigde.

Van toepassing op

Zie ook