WindowsAuthenticationModule.Authenticate 事件

定义

应用程序对当前请求进行身份验证时发生。

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

事件类型

示例

下面的代码示例使用 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

注解

事件 Authenticate 在 事件期间 AuthenticateRequest 引发。

可以通过在 Authenticate global.asax 文件中为 ASP.NET 应用程序指定名为 WindowsAuthentication_OnAuthenticate 的子例程来访问 类的 事件WindowsAuthenticationModule

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

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

备注

在集成模式下运行的 IIS 7.0 中,Authenticate启用 ASP.NET WindowsAuthenticationModule 和 IIS AnonymousAuthenticationModule 模块时,不会引发 的 事件WindowsAuthenticationModule。 在此方案中,若要接收身份验证通知,请 AuthenticateRequest 订阅 实例的 HttpApplication 事件。 有关集成模式下兼容性问题的详细信息,请参阅 将 ASP.NET 应用程序从 IIS 6.0 移动到 IIS 7.0

适用于

另请参阅