Aracılığıyla paylaş


FormsAuthenticationModule.Authenticate Olay

Tanım

Uygulama geçerli isteğin kimliğini doğruladığında gerçekleşir.

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 

Olay Türü

Örnekler

Aşağıdaki kod örneği, FormsAuthentication_OnAuthenticate olayını kullanarak geçerlinin HttpContext özelliğini özel Identityolan bir GenericPrincipal nesneye ayarlarUser.

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

Açıklamalar

Olay Authenticate , olay sırasında AuthenticateRequest oluşturulur.

ASP.NET uygulamanızın FormsAuthenticationModule Global.asax dosyasında FormsAuthentication_OnAuthenticate adlı bir alt yordam belirterek sınıfının olayını işleyebilirsinizAuthenticate.

geçerli özelliğini özel IPrincipal bir nesne olarak ayarlamak User için FormsAuthentication_OnAuthenticate olayına sağlanan özelliğini kullanabilirsinizFormsAuthenticationEventArgsUser.HttpContext FormsAuthentication_OnAuthenticate olayı sırasında özelliği için User bir değer belirtmezseniz, tanımlama bilgisinde veya URL'de form kimlik doğrulama bileti tarafından sağlanan kimlik kullanılır.

FormsAuthentication_OnAuthenticate olayı yalnızca kimlik doğrulama modu uygulamanın yapılandırma dosyasının authentication Öğesi (ASP.NET Ayarlar Şeması) öğesinde olarak ayarlandığında Forms ve FormsAuthenticationModule uygulama için etkin bir HTTP modülü olduğunda oluşturulur.

Şunlara uygulanır

Ayrıca bkz.