WindowsAuthenticationEventArgs.Identity 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
它會把 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 的身份。