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

屬性值

傳遞至 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 所提供的 Windows 身分識別和目前的 HttpContext 建構 WindowsAuthenticationEventArgs 物件,並將它傳遞至WindowsAuthentication_OnAuthenticate事件。

如果 IIS 使用匿名驗證, Identity 則 屬性會設定為 方法所傳回的 GetAnonymous 身分識別。

適用於

另請參閱