WindowsAuthenticationEventHandler 委托

定义

表示处理 WindowsAuthenticationModuleWindowsAuthentication_OnAuthenticate 事件的方法。Represents the method that handles the WindowsAuthentication_OnAuthenticate event of a WindowsAuthenticationModule.

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

参数

sender
Object

事件源。The source of the event.

e
WindowsAuthenticationEventArgs

包含事件数据的 WindowsAuthenticationEventArgsA WindowsAuthenticationEventArgs that contains the event data.

继承
WindowsAuthenticationEventHandler

示例

下面的代码示例使用WindowsAuthentication_OnAuthenticate事件将当前User HttpContext的属性设置为自定义IPrincipal对象。The following code example uses the WindowsAuthentication_OnAuthenticate event to set the User property of the current HttpContext to a custom IPrincipal object.

public void WindowsAuthentication_OnAuthenticate(object sender, WindowsAuthenticationEventArgs args)
{
  if (!args.Identity.IsAnonymous)
  {
    args.User = new Samples.AspNet.Security.MyPrincipal(args.Identity);
  }
}
Public Sub WindowsAuthentication_OnAuthenticate(sender As Object, args As WindowsAuthenticationEventArgs)
  If Not args.Identity.IsAnonymous Then
    args.User = New Samples.AspNet.Security.MyPrincipal(args.Identity)
  End If
End Sub

注解

委托是WindowsAuthenticationModule Authenticate为类的事件定义的。 WindowsAuthenticationEventHandlerThe WindowsAuthenticationEventHandler delegate is defined for the Authenticate event of the WindowsAuthenticationModule class. 可以通过在 ASP.NET Authenticate应用程序的WindowsAuthenticationModule global.asax 文件中指定名为WindowsAuthentication_OnAuthenticate的子例程来访问类的事件。You can access the Authenticate event of the WindowsAuthenticationModule class by specifying a subroutine named WindowsAuthentication_OnAuthenticate in the Global.asax file for your ASP.NET application. Authenticate 事件AuthenticateRequest在事件期间引发。The Authenticate event is raised during the AuthenticateRequest event.

使用 IIS WindowsAuthenticationEventArgs提供的Windows 标识WindowsAuthenticationModule构造对象,并将HttpContext其传递给 WindowsAuthentication_OnAuthenticate 事件。The WindowsAuthenticationModule constructs a WindowsAuthenticationEventArgs object using the Windows identity supplied by IIS and the current HttpContext and passes it to the WindowsAuthentication_OnAuthenticate event.

可以使用提供给User WindowsAuthentication_OnAuthenticate事件UserWindowsAuthenticationEventArgs对象的属性, 将当前HttpContext的属性设置为自定义IPrincipal对象。You can use the User property of the WindowsAuthenticationEventArgs object supplied to the WindowsAuthentication_OnAuthenticate event to set the User property of the current HttpContext to a custom IPrincipal object. 如果未在User WindowsAuthentication_OnAuthenticate事件期间为属性指定值, 则 IIS 提供的 Windows 标识将用作当前请求的标识。If you do not specify a value for the User property during the WindowsAuthentication_OnAuthenticate event, the Windows identity supplied by IIS is used as the identity for the current request. 如果 IIS 使用匿名身份验证, 则Identity WindowsAuthenticationEventArgs对象的属性将设置为该GetAnonymous方法返回的标识。If IIS uses anonymous authentication, then the Identity property of the WindowsAuthenticationEventArgs object is set to the identity returned by the GetAnonymous method.

仅当身份验证Mode Windows设置为, 并且是应用程序的活动HTTP模块时,才会引发WindowsAuthentication_OnAuthenticateWindowsAuthenticationModule事件。The WindowsAuthentication_OnAuthenticate event is only raised when the authentication Mode is set to Windows and the WindowsAuthenticationModule is an active HTTP module for the application.

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。Gets an object that represents the method represented by the specified delegate.

适用于

另请参阅