UserPrincipal.FindByIdentity 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳一個與指定身份值相符的使用者主物件。
多載
| 名稱 | Description |
|---|---|
| FindByIdentity(PrincipalContext, IdentityType, String) |
回傳一個符合指定身份類型與值的使用者主物件。 這個版本的 FindByIdentity 方法會決定識別值的格式。 |
| FindByIdentity(PrincipalContext, String) |
回傳一個與指定身份值相符的使用者主物件。 |
FindByIdentity(PrincipalContext, IdentityType, String)
- 來源:
- User.cs
- 來源:
- 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
一個 IdentityType 列舉值,用來指定參數的 identityValue 格式。
- identityValue
- String
使用者主體的身份。 此參數可以是列舉中包含 IdentityType 的任何格式。
傳回
一個 UserPrincipal 符合指定身份值與型別的物件,若未找到匹配則為空物件。
例外狀況
發現多個與目前使用者物件相符的使用者主物件。
單位值並非有效的 IdentityType 枚舉值。
範例
以下程式碼連接當地電腦商店。 由於建構子中未指定 PrincipalContext 憑證,因此使用執行緒中使用者的憑證。
會進行搜尋以找到擁有 SamAccountName 「Guest」的使用者。
若找到該使用者,會進行檢查以判斷該使用者的帳號是否已啟用。 如果帳號未啟用,範例程式碼會啟用該帳戶。
PrincipalContext ctx = new PrincipalContext(ContextType.Machine);
UserPrincipal usr = UserPrincipal.FindByIdentity(ctx,
IdentityType.SamAccountName,
"Guest");
if(usr != null)
{
if (!usr.Enabled)
usr.Enabled = true;
usr.Save();
usr.Dispose();
}
ctx.Dispose();
適用於
FindByIdentity(PrincipalContext, String)
- 來源:
- User.cs
- 來源:
- 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 符合指定身份值的物件,若未找到匹配則為空。
例外狀況
發現多個與目前使用者物件相符的使用者主物件。