UserPrincipal.FindByIdentity Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a user principal object that matches the specified identity value.
FindByIdentity(PrincipalContext, IdentityType, String) |
Returns a user principal object that matches the specified identity type, and value. This version of the FindByIdentity method determines the format of the identity value. |
FindByIdentity(PrincipalContext, String) |
Returns a user principal object that matches the specified identity value. |
- Source:
- User.cs
- Source:
- User.cs
- Source:
- User.cs
Returns a user principal object that matches the specified identity type, and value. This version of the FindByIdentity method determines the format of the identity value.
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
Parameters
- context
- PrincipalContext
The PrincipalContext that specifies the server or domain against which operations are performed.
- identityType
- IdentityType
A IdentityType enumeration value that specifies the format of the identityValue
parameter.
- identityValue
- String
The identity of the user principal. This parameter can be any format that is contained in the IdentityType enumeration.
Returns
A UserPrincipal object that matches the specified identity value and type, or null if no matches are found.
Exceptions
Multiple user principal objects matching the current user object were found.
The identity value is not a valid IdentityType enumeration value.
Examples
The following code connects to the local computer store. Since the credentials are not specified in the PrincipalContext constructor, the credentials of the user running the current thread are used.
A search is performed to find the user who has SamAccountName "Guest".
If the user is found, a check is performed to determine whether this user's account is enabled. If the account is not enabled, the example code enables it.
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();
Applies to
.NET 9 (package-provided) και άλλες εκδόσεις
Προϊόν | Εκδόσεις |
---|---|
.NET | 8 (package-provided), 9 (package-provided) |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
- Source:
- User.cs
- Source:
- User.cs
- Source:
- User.cs
Returns a user principal object that matches the specified identity value.
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
Parameters
- context
- PrincipalContext
The PrincipalContext that specifies the server or domain against which operations are performed.
- identityValue
- String
The identity of the user principal. This parameter can be any format that is contained in the IdentityType enumeration.
Returns
A UserPrincipal object that matches the specified identity value, or null if no matches are found.
Exceptions
Multiple user principal objects matching the current user object were found.
Applies to
.NET 9 (package-provided) και άλλες εκδόσεις
Προϊόν | Εκδόσεις |
---|---|
.NET | 8 (package-provided), 9 (package-provided) |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
.NET σχόλια
.NET είναι ένα έργο ανοιχτού κώδικα. Επιλέξτε μια σύνδεση για να παρέχετε σχόλια: