다음을 통해 공유


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 이벤트를 사용 하 여 사용자 지정Identity이 있는 개체에 GenericPrincipal 현재 HttpContext 속성을 설정 User 합니다.

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 .

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

FormsAuthentication_OnAuthenticate 이벤트에 제공된 속성을 사용하여 FormsAuthenticationEventArgsUser 현재 HttpContext 속성을 사용자 지정 IPrincipal 개체로 설정할 User 수 있습니다. FormsAuthentication_OnAuthenticate 이벤트 중에 속성 값을 User 지정하지 않으면 쿠키 또는 URL의 양식 인증 티켓에서 제공하는 ID가 사용됩니다.

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

적용 대상

추가 정보