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 屬性,將目前 HttpContext 的 屬性設定 User 為自訂 IPrincipal 物件。

如果您在WindowsAuthentication_OnAuthenticate事件期間未指定 屬性的值 User ,IIS 所提供的 Windows 身分識別會作為目前要求的身分識別。 如果 IIS 使用匿名驗證,則 Identity 屬性會設定為 方法所傳回的 GetAnonymous 身分識別。

適用於

另請參閱