다음을 통해 공유


DefaultAuthenticationEventHandler 대리자

정의

DefaultAuthentication_OnAuthenticate 이벤트를 처리하는 메서드를 DefaultAuthenticationModule나타냅니다.

public delegate void DefaultAuthenticationEventHandler(System::Object ^ sender, DefaultAuthenticationEventArgs ^ e);
public delegate void DefaultAuthenticationEventHandler(object sender, DefaultAuthenticationEventArgs e);
type DefaultAuthenticationEventHandler = delegate of obj * DefaultAuthenticationEventArgs -> unit
Public Delegate Sub DefaultAuthenticationEventHandler(sender As Object, e As DefaultAuthenticationEventArgs)

매개 변수

sender
Object

이벤트의 출처입니다.

e
DefaultAuthenticationEventArgs

이벤트 데이터를 포함하는 A DefaultAuthenticationEventArgs 입니다.

예제

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

메모

DefaultAuthentication_OnAuthenticate 이벤트는 이벤트 전에 발생합니다AuthorizeRequest. 따라서 현재 HttpContext 속성을 사용자 지정 ID로 설정 User 하면 애플리케이션의 동작에 영향을 줄 수 있습니다. 예를 들어 클래스를 FormsAuthentication 사용 중이고 인증된 사용자만 사이트에 액세스할 수 있도록 하는 경우 섹션을 사용하고 authorization 지정하면 <deny users="?" />이 샘플 deny 에서는 사용자가 "기본값"이라는 이름을 가지기 때문에 요소가 무시됩니다. 대신 인증된 사용자만 사이트에 액세스할 수 있도록 지정 <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

설명

DefaultAuthenticationEventHandler 대리자는 클래스의 Authenticate 이벤트에 대해 정의됩니다DefaultAuthenticationModule. ASP.NET 애플리케이션의 DefaultAuthenticationModule Global.asax 파일에서 DefaultAuthentication_OnAuthenticate이라는 서브루틴을 지정하여 클래스의 이벤트에 액세스할 Authenticate 수 있습니다. 이벤트는 Authenticate 이벤트 후에 AuthenticateRequest 발생하며 현재 HttpContext 속성이 User 개체로 IPrincipal 채워지도록 하는 데 사용됩니다.

DefaultAuthentication_OnAuthenticate 이벤트에 제공된 개체의 DefaultAuthenticationEventArgs 속성을 사용하여 Context 현재 HttpContext 속성을 사용자 지정 IPrincipal 개체로 설정할 User 수 있습니다. DefaultAuthentication_OnAuthenticate 이벤트 DefaultAuthenticationModule 중에 제공된 속성의 HttpContext 값을 User 지정하지 않으면 사용자 정보가 없는 개체로 속성을 HttpContextGenericPrincipal 설정합니다User.

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

확장명 메서드

Name Description
GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.

적용 대상