通过


WindowsAuthenticationEventHandler 委托

定义

表示处理 WindowsAuthentication_OnAuthenticate 事件 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

事件源。

示例

下面的代码示例使用 WindowsAuthentication_OnAuthenticate 事件将当前HttpContext对象的属性设置为User自定义IPrincipal对象。

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

注解

委托 WindowsAuthenticationEventHandler 是为 Authenticate 类的事件 WindowsAuthenticationModule 定义的。 可以通过在 global.asax 文件中为 ASP.NET 应用程序指定名为 WindowsAuthentication_OnAuthenticate 的子例程来访问Authenticate类的事件。WindowsAuthenticationModule 事件 Authenticate 期间 AuthenticateRequest 引发该事件。

WindowsAuthenticationModule函数使用 IIS 提供的 Windows 标识和当前HttpContext对象构造WindowsAuthenticationEventArgs对象,并将其传递给WindowsAuthentication_OnAuthenticate事件。

可以使用User提供给WindowsAuthentication_OnAuthenticate事件的对象的属性WindowsAuthenticationEventArgs将当前HttpContext对象的属性设置为User自定义IPrincipal对象。 如果在WindowsAuthentication_OnAuthenticate事件期间未指定User属性的值,IIS 提供的 Windows 标识将用作当前请求的标识。 如果 IIS 使用匿名身份验证,则 Identity 对象的属性 WindowsAuthenticationEventArgs 将设置为该方法返回的 GetAnonymous 标识。

仅当身份验证设置为WindowsMode事件并且WindowsAuthenticationModule是应用程序的活动 HTTP 模块时,才会引发WindowsAuthentication_OnAuthenticate事件。

扩展方法

名称 说明
GetMethodInfo(Delegate)

获取一个对象,该对象表示由指定委托表示的方法。

适用于

另请参阅