Share via


DefaultAuthenticationModule.Authenticate 이벤트

정의

요청이 인증된 후에 발생합니다.

public:
 event System::Web::Security::DefaultAuthenticationEventHandler ^ Authenticate;
public event System.Web.Security.DefaultAuthenticationEventHandler Authenticate;
member this.Authenticate : System.Web.Security.DefaultAuthenticationEventHandler 
Public Custom Event Authenticate As DefaultAuthenticationEventHandler 

이벤트 유형

예제

다음 코드 예제에서는 DefaultAuthentication_OnAuthenticate 이벤트를 사용하여 현재 HttpContext instance 속성이 User 인지 여부를 테스트합니다null. 속성이 인 User 경우 샘플은 null현재 HttpContext instance GenericPrincipal 속성을 개체의 GenericPrincipalIdentity 값이 "default"인 개체 GenericIdentityName 설정합니다User.

참고

합니다 DefaultAuthentication_OnAuthenticate 이벤트가 발생 하기 전에 AuthorizeRequest 이벤트입니다. 결과적으로 설정 하는 경우는 User 속성이 현재 HttpContext 인스턴스는 사용자 지정 서비스 id에 영향을 주므로 애플리케이션의 동작입니다. 예를 들어 클래스를 FormsAuthentication 사용하고 인증된 사용자만 사이트에 액세스할 수 있도록 권한 부여 구성 섹션에서 지정 <deny users="?" /> 하는 경우 이 샘플에서는 사용자가 이름이 "기본값"인 이름을 가지기 때문에 거부 요소가 무시됩니다. 대신 인증된 사용자만 사이트에 액세스할 수 있도록 을 지정 <deny users="default" /> 합니다.

public void DefaultAuthentication_OnAuthenticate(object sender,
                                                 DefaultAuthenticationEventArgs args)
{
  if (args.Context.User == null)
    args.Context.User = 
      new System.Security.Principal.GenericPrincipal(
        new System.Security.Principal.GenericIdentity("default"),
        new String[0]);
}
Public Sub DefaultAuthentication_OnAuthenticate(sender As Object, _
                                                args As DefaultAuthenticationEventArgs)
  If args.Context.User Is Nothing Then
    args.Context.User = _
      new System.Security.Principal.GenericPrincipal( _
        new System.Security.Principal.GenericIdentity("default"), _
        new String(0) {})
  End If
End Sub

설명

이벤트는 Authenticate 이벤트 이후에 발생합니다 AuthenticateRequest . 현재 HttpContext instance 속성이 User 개체로 IPrincipal 채워지도록 하는 데 사용됩니다.

액세스할 수 있습니다는 Authenticate 의 이벤트를 DefaultAuthenticationModule 라는 서브루틴을 지정 하 여 클래스 DefaultAuthentication_OnAuthenticate 애플리케이션의 Global.asax 파일.

DefaultAuthentication_OnAuthenticate 이벤트에서 개체의 DefaultAuthenticationEventArgs 속성을 사용하여 Context 현재 HttpContextinstance 속성을 사용자 지정 IPrincipal 개체로 설정할 User 수 있습니다. 에 대 User 한 값을 지정 하지 않으면는 속성은 DefaultAuthenticationModule 사용자 정보를 포함 하는 개체에 GenericPrincipal instance 속성을 HttpContext 설정 User 합니다.

DefaultAuthentication_OnAuthenticate 이벤트 후에 발생 합니다 AuthenticateRequest 이벤트 전과 AuthorizeRequest 이벤트. 애플리케이션에 대한 액세스를 거부하거나 허용할 사용자 이름에 따라 달라지는 섹션이 있는 경우 authorization 현재 HttpContext instance 속성을 수정하면 User 애플리케이션의 동작에 영향을 줄 수 있습니다. 구성에서 권한 부여 섹션을 지정할 때 DefaultAuthentication_OnAuthenticate 이벤트 중에 설정한 사용자 이름을 고려해야 합니다.

참고

웹 애플리케이션은 통합된 모드의 IIS 7.0에서 실행 중인 경우는 Authenticate 의 이벤트는 DefaultAuthenticationModule 발생 하지 않습니다. mode인증 구성 요소의 특성이 "None"으로 설정되고 애플리케이션이 이벤트를 PlatformNotSupportedException 구독하는 Authenticate 경우 오류가 발생합니다. 이 시나리오에서는 인증 알림 수신, 구독에 AuthenticateRequest 의 이벤트는 HttpApplication 인스턴스. 통합된 모드의 호환성 문제에 대 한 자세한 내용은 참조 하세요. IIS 6.0에서 IIS 7.0 ASP.NET 애플리케이션 이동합니다.

적용 대상

추가 정보