FormsAuthenticationEventHandler Delegát

Definice

Představuje metodu, která zpracovává událost FormsAuthentication_OnAuthenticate objektu 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)

Parametry

sender
Object

Zdroj události

e
FormsAuthenticationEventArgs

A FormsAuthenticationEventArgs , který obsahuje data události.

Příklady

Následující příklad kódu používá událost FormsAuthentication_OnAuthenticate k nastavení User vlastnosti current HttpContext na GenericPrincipal objekt s vlastní 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

Poznámky

Delegát FormsAuthenticationEventHandler je definován pro Authenticate událost FormsAuthenticationModule třídy. K události FormsAuthenticationModule třídy můžete získat přístup Authenticate zadáním podprogramu s názvem FormsAuthentication_OnAuthenticate v souboru Global.asax pro vaši aplikaci ASP.NET. Událost Authenticate je vyvolána během události AuthenticateRequest .

Objekt FormsAuthenticationModule vytvoří FormsAuthenticationEventArgs pomocí aktuálního HttpContext objektu a předá ho události FormsAuthentication_OnAuthenticate .

Pomocí vlastnosti objektu zadaného FormsAuthenticationEventArgsdo události FormsAuthentication_OnAuthenticate můžete User nastavit User vlastnost aktuálního HttpContext objektu na vlastní IPrincipal objekt. Pokud během události FormsAuthentication_OnAuthenticate nezadáte hodnotu User vlastnosti, použije se identita zadaná lístkem ověřování formulářů v souboru cookie nebo adrese URL.

Událost FormsAuthentication_OnAuthenticate se vyvolá pouze v případě, že je ověřování Mode nastavené na Forms a FormsAuthenticationModule je aktivní modul HTTP pro aplikaci.

Metody rozšíření

GetMethodInfo(Delegate)

Získá objekt, který představuje metodu reprezentovanou zadaným delegátem.

Platí pro

Viz také