WindowsAuthenticationEventArgs.User 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 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屬性把 current HttpContext 的屬性設定User成自訂IPrincipal物件。
如果你在WindowsAuthentication_OnAuthenticate事件中未指定屬性值User,則使用 IIS 提供的 Windows 身份作為當前請求的身份。 若 IIS 使用匿名認證,則 Identity 該屬性會設定為方法回傳 GetAnonymous 的身份。