WindowsAuthenticationEventArgs.User 属性
定义
获取或设置要与当前请求关联的 IPrincipal 对象。Gets or sets the IPrincipal object to be associated with the current request.
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 对象。The IPrincipal object to be associated with the current request.
示例
下面的代码示例使用 WindowsAuthentication_OnAuthenticate 事件将 User 当前的属性设置 HttpContext 为自定义 IPrincipal 对象。The following code example uses the WindowsAuthentication_OnAuthenticate event to set the User property of the current HttpContext to a custom IPrincipal object.
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 对象。You can use the User property to set the User property of the current HttpContext to a custom IPrincipal object.
如果未在 User WindowsAuthentication_OnAuthenticate 事件期间为属性指定值,则 IIS 提供的 Windows 标识将用作当前请求的标识。If you do not specify a value for the User property during the WindowsAuthentication_OnAuthenticate event, the Windows identity supplied by IIS is used as the identity for the current request. 如果 IIS 使用匿名身份验证,则 Identity 属性将设置为该方法返回的标识 GetAnonymous 。If IIS uses anonymous authentication, then the Identity property is set to the identity returned by the GetAnonymous method.