共用方式為


WindowsIdentity 類別

定義

表示 Windows 使用者。

public ref class WindowsIdentity : System::Security::Claims::ClaimsIdentity, IDisposable, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public ref class WindowsIdentity : System::Security::Claims::ClaimsIdentity, IDisposable
public ref class WindowsIdentity : System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable, System::Security::Principal::IIdentity
public ref class WindowsIdentity : IDisposable, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable, System::Security::Principal::IIdentity
public class WindowsIdentity : System.Security.Claims.ClaimsIdentity, IDisposable, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
public class WindowsIdentity : System.Security.Claims.ClaimsIdentity, IDisposable
[System.Serializable]
public class WindowsIdentity : System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable, System.Security.Principal.IIdentity
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class WindowsIdentity : IDisposable, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable, System.Security.Principal.IIdentity
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class WindowsIdentity : System.Security.Claims.ClaimsIdentity, IDisposable, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
type WindowsIdentity = class
    inherit ClaimsIdentity
    interface IDisposable
    interface IDeserializationCallback
    interface ISerializable
type WindowsIdentity = class
    inherit ClaimsIdentity
    interface IDisposable
[<System.Serializable>]
type WindowsIdentity = class
    interface IIdentity
    interface ISerializable
    interface IDeserializationCallback
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type WindowsIdentity = class
    interface IIdentity
    interface ISerializable
    interface IDeserializationCallback
    interface IDisposable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type WindowsIdentity = class
    inherit ClaimsIdentity
    interface ISerializable
    interface IDeserializationCallback
    interface IDisposable
Public Class WindowsIdentity
Inherits ClaimsIdentity
Implements IDeserializationCallback, IDisposable, ISerializable
Public Class WindowsIdentity
Inherits ClaimsIdentity
Implements IDisposable
Public Class WindowsIdentity
Implements IDeserializationCallback, IIdentity, ISerializable
Public Class WindowsIdentity
Implements IDeserializationCallback, IDisposable, IIdentity, ISerializable
繼承
WindowsIdentity
繼承
WindowsIdentity
屬性
實作

範例

下列範例顯示 類別成員的使用 WindowsIdentity 。 如需示範如何透過對 Unmanaged Win32 LogonUser 函式的呼叫取得 Windows 帳戶令牌,以及使用該令牌來模擬其他使用者的範例,請參閱 類別 WindowsImpersonationContext

using namespace System;
using namespace System::Security::Principal;
void IntPtrConstructor( IntPtr logonToken );
void IntPtrStringConstructor( IntPtr logonToken );
void IntPrtStringTypeBoolConstructor( IntPtr logonToken );
void IntPtrStringTypeConstructor( IntPtr logonToken );
void UseProperties( IntPtr logonToken );
IntPtr LogonUser();
void GetAnonymousUser();
void ImpersonateIdentity( IntPtr logonToken );

[STAThread]
int main()
{
   
   // Retrieve the Windows account token for the current user.
   IntPtr logonToken = LogonUser();
   
   // Constructor implementations.
   IntPtrConstructor( logonToken );
   IntPtrStringConstructor( logonToken );
   IntPtrStringTypeConstructor( logonToken );
   IntPrtStringTypeBoolConstructor( logonToken );
   
   // Property implementations.
   UseProperties( logonToken );
   
   // Method implementations.
   GetAnonymousUser();
   ImpersonateIdentity( logonToken );
   Console::WriteLine( "This sample completed successfully; "
   "press Enter to exit." );
   Console::ReadLine();
}


// Create a WindowsIdentity object for the user represented by the
// specified Windows account token.
void IntPtrConstructor( IntPtr logonToken )
{
   
   // Construct a WindowsIdentity object using the input account token.
   WindowsIdentity^ windowsIdentity = gcnew WindowsIdentity( logonToken );
   
   Console::WriteLine( "Created a Windows identity object named {0}.", windowsIdentity->Name );
}

// Create a WindowsIdentity object for the user represented by the
// specified account token and authentication type.
void IntPtrStringConstructor( IntPtr logonToken )
{
   
   // Construct a WindowsIdentity object using the input account token 
   // and the specified authentication type.
   String^ authenticationType = "WindowsAuthentication";
   WindowsIdentity^ windowsIdentity = gcnew WindowsIdentity( logonToken,authenticationType );
   
   Console::WriteLine( "Created a Windows identity object named {0}.", windowsIdentity->Name );
}



// Create a WindowsIdentity object for the user represented by the
// specified account token, authentication type and Windows account
// type.
void IntPtrStringTypeConstructor( IntPtr logonToken )
{
   
   // Construct a WindowsIdentity object using the input account token,
   // and the specified authentication type and Windows account type.
   String^ authenticationType = "WindowsAuthentication";
   WindowsAccountType guestAccount = WindowsAccountType::Guest;
   WindowsIdentity^ windowsIdentity = gcnew WindowsIdentity( logonToken,authenticationType,guestAccount );
   
   Console::WriteLine( "Created a Windows identity object named {0}.", windowsIdentity->Name );
}

// Create a WindowsIdentity object for the user represented by the
// specified account token, authentication type, Windows account type and
// Boolean authentication flag.
void IntPrtStringTypeBoolConstructor( IntPtr logonToken )
{
   
   // Construct a WindowsIdentity object using the input account token,
   // and the specified authentication type, Windows account type, and
   // authentication flag.
   String^ authenticationType = "WindowsAuthentication";
   WindowsAccountType guestAccount = WindowsAccountType::Guest;
   bool isAuthenticated = true;
   WindowsIdentity^ windowsIdentity = gcnew WindowsIdentity( logonToken,authenticationType,guestAccount,isAuthenticated );
   
   Console::WriteLine( "Created a Windows identity object named {0}.", windowsIdentity->Name );
}

// Access the properties of a WindowsIdentity object.
void UseProperties( IntPtr logonToken )
{
   WindowsIdentity^ windowsIdentity = gcnew WindowsIdentity( logonToken );
   String^ propertyDescription = "The windows identity named ";
   
   // Retrieve the Windows logon name from the Windows identity object.
   propertyDescription = String::Concat( propertyDescription, windowsIdentity->Name );
   
   // Verify that the user account is not considered to be an Anonymous
   // account by the system.
   if (  !windowsIdentity->IsAnonymous )
   {
      propertyDescription = String::Concat( propertyDescription, ", is not an Anonymous account" );
   }

   
   // Verify that the user account has been authenticated by Windows.
   if ( windowsIdentity->IsAuthenticated )
   {
      propertyDescription = String::Concat( propertyDescription, ", is authenticated" );
   }
   
   // Verify that the user account is considered to be a System account
   // by the system.
   if ( windowsIdentity->IsSystem )
   {
      propertyDescription = String::Concat( propertyDescription, ", is a System account" );
   }
   
   // Verify that the user account is considered to be a Guest account
   // by the system.
   if ( windowsIdentity->IsGuest )
   {
      propertyDescription = String::Concat( propertyDescription, ", is a Guest account" );
   }
   
   // Retrieve the authentication type for the 
   String^ authenticationType = windowsIdentity->AuthenticationType;
   
   // Append the authenication type to the output message.
   if ( authenticationType != nullptr )
   {
      propertyDescription = String::Format( "{0} and uses {1} authentication type.", propertyDescription, authenticationType );
   }
   
   Console::WriteLine( propertyDescription );
}


// Retrieve the account token from the current WindowsIdentity object
// instead of calling the unmanaged LogonUser method in the advapi32.dll.
IntPtr LogonUser()
{
   
   IntPtr accountToken = WindowsIdentity::GetCurrent()->Token;
   
   return accountToken;
}


// Get the WindowsIdentity object for an Anonymous user.
void GetAnonymousUser()
{
   
   // Retrieve a WindowsIdentity object that represents an anonymous
   // Windows user.
   WindowsIdentity^ windowsIdentity = WindowsIdentity::GetAnonymous();
   
}


// Impersonate a Windows identity.
void ImpersonateIdentity( IntPtr logonToken )
{
   
   // Retrieve the Windows identity using the specified token.
   WindowsIdentity^ windowsIdentity = gcnew WindowsIdentity( logonToken );
   
   // Create a WindowsImpersonationContext object by impersonating the
   // Windows identity.
   WindowsImpersonationContext^ impersonationContext = windowsIdentity->Impersonate();
   Console::WriteLine( "Name of the identity after impersonation: {0}.", WindowsIdentity::GetCurrent()->Name );
   
   // Stop impersonating the user.
   impersonationContext->Undo();
   
   // Check the identity name.
   Console::Write( "Name of the identity after performing an Undo on the" );
   Console::WriteLine( " impersonation: {0}", WindowsIdentity::GetCurrent()->Name );
}
using System;
using System.Security.Principal;

class WindowsIdentityMembers
{
    [STAThread]
    static void Main(string[] args)
    {
        // Retrieve the Windows account token for the current user.
        IntPtr logonToken = LogonUser();

        // Constructor implementations.
        IntPtrConstructor(logonToken);
        IntPtrStringConstructor(logonToken);
        IntPtrStringTypeConstructor(logonToken);
        IntPrtStringTypeBoolConstructor(logonToken);

        // Property implementations.
        UseProperties(logonToken);

        // Method implementations.
        GetAnonymousUser();
        ImpersonateIdentity(logonToken);

        Console.WriteLine("This sample completed successfully; " +
            "press Enter to exit.");
        Console.ReadLine();
    }

    // Create a WindowsIdentity object for the user represented by the
    // specified Windows account token.
    private static void IntPtrConstructor(IntPtr logonToken)
    {
        // Construct a WindowsIdentity object using the input account token.
        WindowsIdentity windowsIdentity = new WindowsIdentity(logonToken);

        Console.WriteLine("Created a Windows identity object named " +
            windowsIdentity.Name + ".");
    }

    // Create a WindowsIdentity object for the user represented by the
    // specified account token and authentication type.
    private static void IntPtrStringConstructor(IntPtr logonToken)
    {
        // Construct a WindowsIdentity object using the input account token 
        // and the specified authentication type.
        string authenticationType = "WindowsAuthentication";
        WindowsIdentity windowsIdentity =
                        new WindowsIdentity(logonToken, authenticationType);

        Console.WriteLine("Created a Windows identity object named " +
            windowsIdentity.Name + ".");
    }

    // Create a WindowsIdentity object for the user represented by the
    // specified account token, authentication type, and Windows account
    // type.
    private static void IntPtrStringTypeConstructor(IntPtr logonToken)
    {
        // Construct a WindowsIdentity object using the input account token,
        // and the specified authentication type, and Windows account type.
        string authenticationType = "WindowsAuthentication";
        WindowsAccountType guestAccount = WindowsAccountType.Guest;
        WindowsIdentity windowsIdentity =
            new WindowsIdentity(logonToken, authenticationType, guestAccount);

        Console.WriteLine("Created a Windows identity object named " +
            windowsIdentity.Name + ".");
    }

    // Create a WindowsIdentity object for the user represented by the
    // specified account token, authentication type, Windows account type, and
    // Boolean authentication flag.
    private static void IntPrtStringTypeBoolConstructor(IntPtr logonToken)
    {
        // Construct a WindowsIdentity object using the input account token,
        // and the specified authentication type, Windows account type, and
        // authentication flag.
        string authenticationType = "WindowsAuthentication";
        WindowsAccountType guestAccount = WindowsAccountType.Guest;
        bool isAuthenticated = true;
        WindowsIdentity windowsIdentity = new WindowsIdentity(
            logonToken, authenticationType, guestAccount, isAuthenticated);

        Console.WriteLine("Created a Windows identity object named " +
            windowsIdentity.Name + ".");
    }
    // Access the properties of a WindowsIdentity object.
    private static void UseProperties(IntPtr logonToken)
    {
        WindowsIdentity windowsIdentity = new WindowsIdentity(logonToken);
        string propertyDescription = "The Windows identity named ";

        // Retrieve the Windows logon name from the Windows identity object.
        propertyDescription += windowsIdentity.Name;

        // Verify that the user account is not considered to be an Anonymous
        // account by the system.
        if (!windowsIdentity.IsAnonymous)
        {
            propertyDescription += " is not an Anonymous account";
        }

        // Verify that the user account has been authenticated by Windows.
        if (windowsIdentity.IsAuthenticated)
        {
            propertyDescription += ", is authenticated";
        }

        // Verify that the user account is considered to be a System account
        // by the system.
        if (windowsIdentity.IsSystem)
        {
            propertyDescription += ", is a System account";
        }
        // Verify that the user account is considered to be a Guest account
        // by the system.
        if (windowsIdentity.IsGuest)
        {
            propertyDescription += ", is a Guest account";
        }

        // Retrieve the authentication type for the 
        String authenticationType = windowsIdentity.AuthenticationType;

        // Append the authenication type to the output message.
        if (authenticationType != null)
        {
            propertyDescription += (" and uses " + authenticationType);
            propertyDescription += (" authentication type.");
        }

        Console.WriteLine(propertyDescription);

        // Display the SID for the owner.
        Console.Write("The SID for the owner is : ");
        SecurityIdentifier si = windowsIdentity.Owner;
        Console.WriteLine(si.ToString());
        // Display the SIDs for the groups the current user belongs to.
        Console.WriteLine("Display the SIDs for the groups the current user belongs to.");
        IdentityReferenceCollection irc = windowsIdentity.Groups;
        foreach (IdentityReference ir in irc)
            Console.WriteLine(ir.Value);
        TokenImpersonationLevel token = windowsIdentity.ImpersonationLevel;
        Console.WriteLine("The impersonation level for the current user is : " + token.ToString());
    }

    // Retrieve the account token from the current WindowsIdentity object
    // instead of calling the unmanaged LogonUser method in the advapi32.dll.
    private static IntPtr LogonUser()
    {
        IntPtr accountToken = WindowsIdentity.GetCurrent().Token;
        Console.WriteLine( "Token number is: " + accountToken.ToString());

        return accountToken;
    }

    // Get the WindowsIdentity object for an Anonymous user.
    private static void GetAnonymousUser()
    {
        // Retrieve a WindowsIdentity object that represents an anonymous
        // Windows user.
        WindowsIdentity windowsIdentity = WindowsIdentity.GetAnonymous();
    }

    // Impersonate a Windows identity.
    private static void ImpersonateIdentity(IntPtr logonToken)
    {
        // Retrieve the Windows identity using the specified token.
        WindowsIdentity windowsIdentity = new WindowsIdentity(logonToken);

        // Create a WindowsImpersonationContext object by impersonating the
        // Windows identity.
        WindowsImpersonationContext impersonationContext =
            windowsIdentity.Impersonate();

        Console.WriteLine("Name of the identity after impersonation: "
            + WindowsIdentity.GetCurrent().Name + ".");
        Console.WriteLine(windowsIdentity.ImpersonationLevel);
        // Stop impersonating the user.
        impersonationContext.Undo();

        // Check the identity name.
        Console.Write("Name of the identity after performing an Undo on the");
        Console.WriteLine(" impersonation: " +
            WindowsIdentity.GetCurrent().Name);
    }
}
Imports System.Security.Principal

Module Module1

    Sub Main()

        ' Retrieve the Windows account token for the current user.
        Dim logonToken As IntPtr = LogonUser()

        ' Constructor implementations.
        IntPtrConstructor(logonToken)
        IntPtrStringConstructor(logonToken)
        IntPtrStringTypeConstructor(logonToken)
        IntPrtStringTypeBoolConstructor(logonToken)

        ' Property implementations.
        UseProperties(logonToken)

        ' Method implementations.
        GetAnonymousUser()
        ImpersonateIdentity(logonToken)

        ' Align interface and conclude application.
        Console.WriteLine(vbCrLf + "This sample completed " + _
            "successfully; press Enter to exit.")
        Console.ReadLine()

    End Sub
    
    ' Create a WindowsIdentity object for the user represented by the
    ' specified Windows account token.
    Private Sub IntPtrConstructor(ByVal logonToken As IntPtr)
        ' Construct a WindowsIdentity object using the input account token.
        Dim windowsIdentity As New WindowsIdentity(logonToken)

        WriteLine("Created a Windows identity object named " + _
            windowsIdentity.Name + ".")
    End Sub
    ' Create a WindowsIdentity object for the user represented by the
    ' specified account token and authentication type.
    Private Sub IntPtrStringConstructor(ByVal logonToken As IntPtr)
        ' Construct a WindowsIdentity object using the input account token 
        ' and the specified authentication type
        Dim authenticationType = "WindowsAuthentication"
        Dim windowsIdentity As _
            New WindowsIdentity(logonToken, authenticationType)

        WriteLine("Created a Windows identity object named " + _
            windowsIdentity.Name + ".")
    End Sub

    ' Create a WindowsIdentity object for the user represented by the
    ' specified account token, authentication type, and Windows account
    ' type.
    Private Sub IntPtrStringTypeConstructor(ByVal logonToken As IntPtr)
        ' Construct a WindowsIdentity object using the input account token,
        ' and the specified authentication type and Windows account type.
        Dim authenticationType As String = "WindowsAuthentication"
        Dim guestAccount As WindowsAccountType = WindowsAccountType.Guest
        Dim windowsIdentity As _
            New WindowsIdentity(logonToken, authenticationType, guestAccount)

        WriteLine("Created a Windows identity object named " + _
            windowsIdentity.Name + ".")
    End Sub

    ' Create a WindowsIdentity object for the user represented by the
    ' specified account token, authentication type, Windows account type,
    ' and Boolean authentication flag.
    Private Sub IntPrtStringTypeBoolConstructor(ByVal logonToken As IntPtr)
        ' Construct a WindowsIdentity object using the input account token,
        ' and the specified authentication type, Windows account type, and
        ' authentication flag.
        Dim authenticationType As String = "WindowsAuthentication"
        Dim guestAccount As WindowsAccountType = WindowsAccountType.Guest
        Dim isAuthenticated As Boolean = True
        Dim windowsIdentity As New WindowsIdentity( _
            logonToken, authenticationType, guestAccount, isAuthenticated)

        WriteLine("Created a Windows identity object named " + _
            windowsIdentity.Name + ".")
    End Sub
        
    ' Access the properties of a WindowsIdentity object.
    Private Sub UseProperties(ByVal logonToken As IntPtr)
        Dim windowsIdentity As New WindowsIdentity(logonToken)
        Dim propertyDescription As String = "The Windows identity named "

        ' Retrieve the Windows logon name from the Windows identity object.
        propertyDescription += windowsIdentity.Name

        ' Verify that the user account is not considered to be an Anonymous
        ' account by the system.
        If Not windowsIdentity.IsAnonymous Then
            propertyDescription += " is not an Anonymous account"
        End If

        ' Verify that the user account has been authenticated by Windows.
        If (windowsIdentity.IsAuthenticated) Then
            propertyDescription += ", is authenticated"
        End If

        ' Verify that the user account is considered to be a System account by
        ' the system.
        If (windowsIdentity.IsSystem) Then
            propertyDescription += ", is a System account"
        End If

        ' Verify that the user account is considered to be a Guest account by
        ' the system.
        If (windowsIdentity.IsGuest) Then
            propertyDescription += ", is a Guest account"
        End If
        Dim authenticationType As String = windowsIdentity.AuthenticationType

        ' Append the authenication type to the output message.
        If (Not authenticationType Is Nothing) Then
            propertyDescription += (" and uses " + authenticationType)
            propertyDescription += (" authentication type.")
        End If

        WriteLine(propertyDescription)

        ' Display the SID for the owner.
        Console.Write("The SID for the owner is : ")
        Dim si As SecurityIdentifier
        si = windowsIdentity.Owner
        Console.WriteLine(si.ToString())
        ' Display the SIDs for the groups the current user belongs to.
        Console.WriteLine("Display the SIDs for the groups the current user belongs to.")
        Dim irc As IdentityReferenceCollection
        Dim ir As IdentityReference
        irc = windowsIdentity.Groups
        For Each ir In irc
            Console.WriteLine(ir.Value)
        Next
        Dim token As TokenImpersonationLevel
        token = windowsIdentity.ImpersonationLevel
        Console.WriteLine("The impersonation level for the current user is : " + token.ToString())
    End Sub
    ' Retrieve the account token from the current WindowsIdentity object
    ' instead of calling the unmanaged LogonUser method in the advapi32.dll.
    Private Function LogonUser() As IntPtr
        Dim accountToken As IntPtr = WindowsIdentity.GetCurrent().Token

        Return accountToken
    End Function

    ' Get the WindowsIdentity object for an Anonymous user.
    Private Sub GetAnonymousUser()
        ' Retrieve a WindowsIdentity object that represents an anonymous
        ' Windows user.
        Dim windowsIdentity As WindowsIdentity
        windowsIdentity = windowsIdentity.GetAnonymous()
    End Sub

    ' Impersonate a Windows identity.
    Private Sub ImpersonateIdentity(ByVal logonToken As IntPtr)
        ' Retrieve the Windows identity using the specified token.
        Dim windowsIdentity As New WindowsIdentity(logonToken)

        ' Create a WindowsImpersonationContext object by impersonating the
        ' Windows identity.
        Dim impersonationContext As WindowsImpersonationContext
        impersonationContext = windowsIdentity.Impersonate()

        WriteLine("Name of the identity after impersonation: " + _
            windowsIdentity.GetCurrent().Name + ".")

        ' Stop impersonating the user.
        impersonationContext.Undo()

        ' Check the identity.
        WriteLine("Name of the identity after performing an Undo on the " + _
            "impersonation: " + windowsIdentity.GetCurrent().Name + ".")
    End Sub
    ' Write out message with carriage return to output textbox.
    Private Sub WriteLine(ByVal message As String)
        Console.WriteLine(message + vbCrLf)
    End Sub

End Module

備註

GetCurrent呼叫 方法以建立WindowsIdentity代表目前用戶的物件。

重要

此型別代表 IDisposable 介面。 當您完成使用型別時,您應該直接或間接處置它。 若要直接處置型別,請呼叫其 try/catch 區塊中的 Dispose 方法。 若要間接處置它,請使用語言建構函式,例如 using (在 C# 中) 或 Using (在 Visual Basic 中)。 如需詳細資訊,請參閱 IDisposable 介面文章中的<使用實作 IDisposable 的物件>一節。

建構函式

WindowsIdentity(IntPtr)

為指定 Windows 帳戶語彙基元所表示的使用者,初始化 WindowsIdentity 類別的新執行個體。

WindowsIdentity(IntPtr, String)

為指定 Windows 帳戶語彙基元和指定驗證 (Authentication) 類型所表示的使用者,初始化 WindowsIdentity 類別的新執行個體。

WindowsIdentity(IntPtr, String, WindowsAccountType)

為指定 Windows 帳戶語彙基元、指定驗證類型和指定 Windows 帳戶類型所代表使用者,初始化 WindowsIdentity 類別的新執行個體。

WindowsIdentity(IntPtr, String, WindowsAccountType, Boolean)

為指定 Windows 帳戶語彙基元、指定驗證類型、指定 Windows 帳戶類型和指定驗證狀態所代表的使用者,初始化 WindowsIdentity 類別的新執行個體。

WindowsIdentity(SerializationInfo, StreamingContext)
已淘汰.

SerializationInfo 資料流中之資訊所表示的使用者,初始化 WindowsIdentity 類別的新執行個體。

WindowsIdentity(String)

為指定使用者主要名稱 (UPN) 所表示的使用者,初始化 WindowsIdentity 類別的新執行個體。

WindowsIdentity(String, String)

為指定使用者主要名稱 (UPN) 和指定驗證類型所代表的使用者,初始化 WindowsIdentity 類別的新執行個體。

WindowsIdentity(WindowsIdentity)

使用指定的 WindowsIdentity 物件,初始化 WindowsIdentity 類別的新執行個體。

欄位

DefaultIssuer

識別預設 ClaimsIdentity 簽發者的名稱。

DefaultNameClaimType

預設名稱宣告型別;Name.

(繼承來源 ClaimsIdentity)
DefaultRoleClaimType

預設角色宣告型別;Role.

(繼承來源 ClaimsIdentity)

屬性

AccessToken

取得這個 SafeAccessTokenHandle 執行個體的這個 WindowsIdentity

Actor

取得或設定已授與委派權限之呼叫方的識別。

(繼承來源 ClaimsIdentity)
AuthenticationType

取得用來識別使用者的驗證類型。

BootstrapContext

取得或設定用來建立此宣告識別的權杖。

(繼承來源 ClaimsIdentity)
Claims

針對這個 Windows 識別所表示的使用者取得所有宣告。

CustomSerializationData

包含衍生類型所提供的任何其他資料。 通常會在呼叫 WriteTo(BinaryWriter, Byte[]) 時設定。

(繼承來源 ClaimsIdentity)
DeviceClaims

取得具有 WindowsDeviceClaim 屬性索引鍵的宣告。

Groups

取得目前 Windows 使用者所屬的群組。

ImpersonationLevel

設定使用者的模擬層級。

IsAnonymous

取得值,指出使用者帳戶是否已經由系統識別為匿名帳戶。

IsAuthenticated

取得值,指出使用者是否已經由 Windows 驗證。

IsGuest

取得值,指出使用者帳戶是否由系統識別為 Guest 帳戶。

IsSystem

取得值,指出使用者帳戶是否由系統識別為 System 帳戶。

Label

取得或設定此宣告識別的標籤。

(繼承來源 ClaimsIdentity)
Name

取得使用者的 Windows 登入名稱。

NameClaimType

取得宣告型別,用來判斷哪些宣告為這個宣告識別的 Name 屬性提供值。

(繼承來源 ClaimsIdentity)
Owner

取得語彙基元擁有人的安全識別項 (SID)。

RoleClaimType

在此宣告身分識別的宣告中,取得將解譯為 .NET 角色的宣告型別。

(繼承來源 ClaimsIdentity)
Token

取得使用者的 Windows 帳戶的語彙基元。

User

取得使用者的安全識別項 (SID)。

UserClaims

取得具有 WindowsUserClaim 屬性索引鍵的宣告。

方法

AddClaim(Claim)

將單一宣告加入至這個宣告識別。

(繼承來源 ClaimsIdentity)
AddClaims(IEnumerable<Claim>)

將宣告清單加入至這個宣告識別。

(繼承來源 ClaimsIdentity)
Clone()

建立目前執行個體複本的新物件。

CreateClaim(BinaryReader)

提供衍生類型的擴充點來建立自訂 Claim

(繼承來源 ClaimsIdentity)
Dispose()

釋放 WindowsIdentity 所使用的所有資源。

Dispose(Boolean)

釋放 WindowsIdentity 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
Finalize()

將目前執行個體所持有的資源釋出。

FindAll(Predicate<Claim>)

擷取符合指定述詞的所有宣告。

(繼承來源 ClaimsIdentity)
FindAll(String)

擷取具有指定宣告型別的所有宣告。

(繼承來源 ClaimsIdentity)
FindFirst(Predicate<Claim>)

擷取符合指定述詞的第一個宣告。

(繼承來源 ClaimsIdentity)
FindFirst(String)

擷取含指定宣告型別的第一個宣告。

(繼承來源 ClaimsIdentity)
GetAnonymous()

傳回可在程式碼中用來做為代表匿名使用者之 Sentinel 值的 WindowsIdentity 物件。 屬性值不代表 Windows 作業系統所使用的內建匿名識別。

GetCurrent()

傳回表示目前 Windows 使用者的 WindowsIdentity 物件。

GetCurrent(Boolean)

傳回表示執行緒或處理程序之 Windows 識別的 WindowsIdentity 物件,視 ifImpersonating 參數的值而定。

GetCurrent(TokenAccessLevels)

使用指定所要的語彙基元存取層級,傳回代表目前 Windows 使用者的 WindowsIdentity 物件。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetObjectData(SerializationInfo, StreamingContext)

將序列化目前 SerializationInfo 物件所需的資料填入 ClaimsIdentity

(繼承來源 ClaimsIdentity)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
HasClaim(Predicate<Claim>)

判斷這個宣告識別是否具有與指定之述詞相符的宣告。

(繼承來源 ClaimsIdentity)
HasClaim(String, String)

判斷這個宣告識別是否具有含指定之型別及值的宣告。

(繼承來源 ClaimsIdentity)
Impersonate()

模擬由 WindowsIdentity 物件所代表的使用者。

Impersonate(IntPtr)

模擬由指定使用者語彙基元所表示的使用者。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
RemoveClaim(Claim)

嘗試從宣告識別移除宣告。

(繼承來源 ClaimsIdentity)
RunImpersonated(SafeAccessTokenHandle, Action)

以模擬的 Windows 身分識別執行指定的動作。 您可以使用 RunImpersonated(SafeAccessTokenHandle, Action) 並提供您的函式做為參數,而不需要使用個人化的方法呼叫並在 WindowsImpersonationContext 中執行您的函式。

RunImpersonated<T>(SafeAccessTokenHandle, Func<T>)

以模擬的 Windows 身分識別執行指定的函式。 您可以使用 RunImpersonated(SafeAccessTokenHandle, Action) 並提供您的函式做為參數,而不需要使用個人化的方法呼叫並在 WindowsImpersonationContext 中執行您的函式。

RunImpersonatedAsync(SafeAccessTokenHandle, Func<Task>)

執行指定的異步動作作為仿真的 Windows 身分識別。

RunImpersonatedAsync<T>(SafeAccessTokenHandle, Func<Task<T>>)

執行指定的異步動作作為仿真的 Windows 身分識別。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)
TryRemoveClaim(Claim)

嘗試從宣告識別移除宣告。

(繼承來源 ClaimsIdentity)
WriteTo(BinaryWriter)

使用 BinaryWriter 序列化。

(繼承來源 ClaimsIdentity)
WriteTo(BinaryWriter, Byte[])

使用 BinaryWriter 序列化。

(繼承來源 ClaimsIdentity)

明確介面實作

IDeserializationCallback.OnDeserialization(Object)

實作 ISerializable 介面並在還原序列化完成時,由還原序列化事件回呼。

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

將具有邏輯內容資訊的 SerializationInfo 物件,設定為需要重新建立此執行內容的執行個體。

適用於