FormsAuthenticationEventHandler Delegált

Definíció

A FormsAuthentication_OnAuthenticate eseményt kezelő metódust FormsAuthenticationModulejelöli.

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)

Paraméterek

sender
Object

Az esemény forrása.

e
FormsAuthenticationEventArgs

Az FormsAuthenticationEventArgs eseményadatokat tartalmazó A.

Példák

Az alábbi példa a FormsAuthentication_OnAuthenticate esemény használatával állítja be az User aktuális HttpContext tulajdonságot egy GenericPrincipal egyéni Identityobjektumra.

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

Megjegyzések

A FormsAuthenticationEventHandler meghatalmazott az osztály eseményéhez Authenticate van definiálvaFormsAuthenticationModule. A Authenticate osztály FormsAuthenticationModule eseményéhez egy FormsAuthentication_OnAuthenticate nevű alrutin megadásával férhet hozzá a ASP.NET-alkalmazás Global.asax fájljában. Az Authenticate esemény az esemény során AuthenticateRequest jön elő.

Az FormsAuthenticationModule objektumot FormsAuthenticationEventArgs az aktuális HttpContext használatával hozza létre, és továbbítja az FormsAuthentication_OnAuthenticate eseménynek.

User Az FormsAuthenticationEventArgs eseményhez megadott objektum tulajdonságával egyéni objektumra User állíthatja HttpContext az aktuális IPrincipal tulajdonságot. Ha az UserFormsAuthentication_OnAuthenticate esemény során nem ad meg értéket a tulajdonsághoz, a rendszer az űrlapok hitelesítési jegye által a cookie-ban vagy URL-címen megadott identitást használja.

A FormsAuthentication_OnAuthenticate esemény csak akkor jön létre, ha a hitelesítés Mode be van állítva Forms , és az FormsAuthenticationModule aktív HTTP-modul az alkalmazás számára.

Bővítő metódusok

Name Description
GetMethodInfo(Delegate)

Lekéri a megadott meghatalmazott által képviselt metódust képviselő objektumot.

A következőre érvényes:

Lásd még