UserPrincipal.FindByIdentity 方法

定義

傳回符合指定的識別值的使用者主體物件。

多載

FindByIdentity(PrincipalContext, IdentityType, String)

傳回符合指定的識別類型和值的使用者主體物件。 這一版的 FindByIdentity 方法會判斷身分識別值的格式。

FindByIdentity(PrincipalContext, String)

傳回符合指定的識別值的使用者主體物件。

FindByIdentity(PrincipalContext, IdentityType, String)

來源:
User.cs
來源:
User.cs
來源:
User.cs

傳回符合指定的識別類型和值的使用者主體物件。 這一版的 FindByIdentity 方法會判斷身分識別值的格式。

public:
 static System::DirectoryServices::AccountManagement::UserPrincipal ^ FindByIdentity(System::DirectoryServices::AccountManagement::PrincipalContext ^ context, System::DirectoryServices::AccountManagement::IdentityType identityType, System::String ^ identityValue);
public static System.DirectoryServices.AccountManagement.UserPrincipal FindByIdentity (System.DirectoryServices.AccountManagement.PrincipalContext context, System.DirectoryServices.AccountManagement.IdentityType identityType, string identityValue);
static member FindByIdentity : System.DirectoryServices.AccountManagement.PrincipalContext * System.DirectoryServices.AccountManagement.IdentityType * string -> System.DirectoryServices.AccountManagement.UserPrincipal
Public Shared Function FindByIdentity (context As PrincipalContext, identityType As IdentityType, identityValue As String) As UserPrincipal

參數

context
PrincipalContext

針對執行的作業指定伺服器或網域的 PrincipalContext

identityType
IdentityType

指定 identityValue 參數格式的 IdentityType 列舉值。

identityValue
String

使用者主體的身分識別。 這個參數可以是 IdentityType 列舉中包含的任何格式。

傳回

符合指定的身分識別值和類型的 UserPrincipal 物件,如果找不到相符項目則為 null。

例外狀況

找到符合目前使用者物件的多個使用者主體物件。

身分識別值不是有效的 IdentityType 列舉值。

範例

下列程式代碼會連線到本機計算機存放區。 由於建構函式中 PrincipalContext 未指定認證,因此會使用執行目前線程的用戶認證。

系統會執行搜尋來尋找具有 SamAccountName “Guest” 的使用者。

如果找到使用者,則會執行檢查以判斷是否啟用此用戶的帳戶。 如果未啟用帳戶,範例程式代碼會加以啟用。

PrincipalContext ctx = new PrincipalContext(ContextType.Machine);  

UserPrincipal usr = UserPrincipal.FindByIdentity(ctx,   
                                           IdentityType.SamAccountName,   
                                           "Guest");  

if(usr != null)  
{  
    if (usr.Enabled == false)  
        usr.Enabled = true;  

    usr.Save();  
    usr.Dispose();  
}  
ctx.Dispose();   

適用於

FindByIdentity(PrincipalContext, String)

來源:
User.cs
來源:
User.cs
來源:
User.cs

傳回符合指定的識別值的使用者主體物件。

public:
 static System::DirectoryServices::AccountManagement::UserPrincipal ^ FindByIdentity(System::DirectoryServices::AccountManagement::PrincipalContext ^ context, System::String ^ identityValue);
public static System.DirectoryServices.AccountManagement.UserPrincipal FindByIdentity (System.DirectoryServices.AccountManagement.PrincipalContext context, string identityValue);
static member FindByIdentity : System.DirectoryServices.AccountManagement.PrincipalContext * string -> System.DirectoryServices.AccountManagement.UserPrincipal
Public Shared Function FindByIdentity (context As PrincipalContext, identityValue As String) As UserPrincipal

參數

context
PrincipalContext

針對執行的作業指定伺服器或網域的 PrincipalContext

identityValue
String

使用者主體的身分識別。 這個參數可以是 IdentityType 列舉中包含的任何格式。

傳回

符合指定的身分識別值的 UserPrincipal 物件,如果找不到相符項目則為 null。

例外狀況

找到符合目前使用者物件的多個使用者主體物件。

適用於