WindowsAuthenticationEventHandler 委托

定义

表示处理 WindowsAuthenticationModuleWindowsAuthentication_OnAuthenticate 事件的方法。

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 标识。

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

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。

适用于

另请参阅