FormsAuthenticationModule.Authenticate 이벤트

정의

애플리케이션이 현재 요청을 인증할 때 발생합니다.

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 

이벤트 유형

예제

다음 코드 예제에서는 합니다 FormsAuthentication_OnAuthenticate 이벤트가 설정를 User 속성이 현재 HttpContextGenericPrincipal 사용자 지정 된 개체 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

설명

합니다 Authenticate 이벤트가 발생 하는 동안는 AuthenticateRequest 이벤트입니다.

처리할 수 있습니다 합니다 Authenticate 의 이벤트를 FormsAuthenticationModule 라는 서브루틴을 지정 하 여 클래스 FormsAuthentication_OnAuthenticate ASP.NET 애플리케이션의 Global.asax 파일에.

사용할 수는 FormsAuthenticationEventArgsUser 속성에 제공 되는 FormsAuthentication_OnAuthenticate 이벤트가 설정를 User 속성이 현재 HttpContext 을 사용자 지정 IPrincipal 개체. 에 대 한 값을 지정 하지 않는 경우는 User 중에 속성을 FormsAuthentication_OnAuthenticate 이벤트 폼 인증 티켓 쿠키 또는 URL에서 제공 하는 id가 사용 됩니다.

FormsAuthentication_OnAuthenticate 인증 모드 설정 된 경우에 이벤트 발생 Forms인증 요소 (ASP.NET 설정 스키마) 의 요소는 애플리케이션의 구성 파일 및 FormsAuthenticationModule 하는 애플리케이션에 대 한 활성 HTTP 모듈입니다.

적용 대상

추가 정보