WindowsAuthenticationEventArgs.Identity 属性

定义

获取传递给 WindowsAuthenticationEventArgs 构造函数的 Windows 标识。

public:
 property System::Security::Principal::WindowsIdentity ^ Identity { System::Security::Principal::WindowsIdentity ^ get(); };
public System.Security.Principal.WindowsIdentity Identity { get; }
member this.Identity : System.Security.Principal.WindowsIdentity
Public ReadOnly Property Identity As WindowsIdentity

属性值

WindowsIdentity

传递给 WindowsAuthenticationEventArgs 构造函数的 Windows 标识。

示例

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

注解

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

如果 IIS 使用匿名身份验证,则 Identity 此属性设置为方法返回 GetAnonymous 的标识。

适用于

另请参阅