通过


WindowsAuthenticationEventArgs.User 属性

定义

获取或设置 IPrincipal 要与当前请求关联的对象。

public:
 property System::Security::Principal::IPrincipal ^ User { System::Security::Principal::IPrincipal ^ get(); void set(System::Security::Principal::IPrincipal ^ value); };
public System.Security.Principal.IPrincipal User { get; set; }
member this.User : System.Security.Principal.IPrincipal with get, set
Public Property User As IPrincipal

属性值

IPrincipal 与当前请求关联的对象。

示例

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

注解

可以使用该 User 属性将 User 当前 HttpContext 对象的属性设置为自定义 IPrincipal 对象。

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

适用于

另请参阅