共用方式為


WindowsAuthenticationEventArgs.Identity 屬性

定義

它會把 Windows 身份傳給 WindowsAuthenticationEventArgs 建構子。

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

屬性值

Windows 身份會傳遞給 WindowsAuthenticationEventArgs 建構子。

範例

以下程式碼範例使用 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 的身份。

適用於

另請參閱