FormsAuthenticationModule.Authenticate Événement

Définition

Se produit lorsque l'application authentifie la demande actuelle.

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 

Type d'événement

Exemples

L’exemple de code suivant utilise l’événement FormsAuthentication_OnAuthenticate pour définir la User propriété du actif HttpContext sur un GenericPrincipal objet qui a un personnalisé 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

Remarques

L’événement Authenticate est déclenché pendant l’événement AuthenticateRequest .

Vous pouvez gérer l’événement Authenticate de la FormsAuthenticationModule classe en spécifiant une sous-routine nommée FormsAuthentication_OnAuthenticate dans le fichier Global.asax pour votre application ASP.NET.

Vous pouvez utiliser la FormsAuthenticationEventArgsUser propriété fournie à l’événement FormsAuthentication_OnAuthenticate pour définir la User propriété du actif HttpContext sur un objet personnalisé IPrincipal . Si vous ne spécifiez pas de valeur pour la User propriété pendant l’événement FormsAuthentication_OnAuthenticate , l’identité fournie par le ticket d’authentification par formulaire dans le cookie ou l’URL est utilisée.

L’événement FormsAuthentication_OnAuthenticate est déclenché uniquement lorsque le mode d’authentification est défini Forms sur dans l’élément d’authentification (schéma des paramètres ASP.NET) du fichier de configuration de l’application et que le FormsAuthenticationModule est un module HTTP actif pour l’application.

S’applique à

Voir aussi