UserPrincipal Constructors

Definition

Initializes a new instance of the UserPrincipal class.

Overloads

UserPrincipal(PrincipalContext)

Initializes a new instance of the UserPrincipal class by using the specified context.

UserPrincipal(PrincipalContext, String, String, Boolean)

Initializes a new instance of the UserPrincipal class by using the specified context, SAM account name, password, and enabled value.

UserPrincipal(PrincipalContext)

Source:
User.cs
Source:
User.cs
Source:
User.cs

Initializes a new instance of the UserPrincipal class by using the specified context.

public UserPrincipal (System.DirectoryServices.AccountManagement.PrincipalContext context);

Parameters

context
PrincipalContext

The PrincipalContext that specifies the server or domain against which operations are performed.

Examples

The following code example connects to the LDAP domain "fabrikam.com" with the username and password initialized in the PrincipalContext constructor to "administrator" and "securelyStoredPassword."

The properties set in the example, such as user name and email address, are created under the container specified in the PrincipalContext constructor: "CN=Users,DC=fabrikam,DC=com."

PrincipalContext ctx = new PrincipalContext(  
                                         ContextType.Domain,  
                                         "fabrikam.com",   
                                         "CN=Users,DC=fabrikam,DC=com",  
                                         "administrator",   
                                         "securelyStoredPassword");   

UserPrincipal usr = new UserPrincipal(ctx);  

usr.Name = "Jim Daly";  
usr.Description = "This is the user account for Jim Daly";  
usr.EmailAddress = "jimdaly@fabrikam.com";  
usr.SetPassword("securelyStoredPassword");  
usr.Save();  

usr.Dispose();  
ctx.Dispose();   

Remarks

The user principal account is not persisted when it is created. To save the account, call the Save method.

Applies to

.NET 9 (package-provided) og andre versjoner
Produkt Versjoner
.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)

UserPrincipal(PrincipalContext, String, String, Boolean)

Source:
User.cs
Source:
User.cs
Source:
User.cs

Initializes a new instance of the UserPrincipal class by using the specified context, SAM account name, password, and enabled value.

public UserPrincipal (System.DirectoryServices.AccountManagement.PrincipalContext context, string samAccountName, string password, bool enabled);

Parameters

context
PrincipalContext

The PrincipalContext that specifies the server or domain against which operations are performed.

samAccountName
String

The SAM account name for this user principal.

password
String

The password for this account.

enabled
Boolean

A Boolean value that specifies whether the account is enabled.

Remarks

The user principal account is not persisted when it is created. To save the account, call the Save method.

Applies to

.NET 9 (package-provided) og andre versjoner
Produkt Versjoner
.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)