UserPrincipal Constructors
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.
Initializes a new instance of the UserPrincipal class.
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. |
- 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);
public UserPrincipal (System.DirectoryServices.AccountManagement.PrincipalContext context);
new System.DirectoryServices.AccountManagement.UserPrincipal : System.DirectoryServices.AccountManagement.PrincipalContext -> System.DirectoryServices.AccountManagement.UserPrincipal
Public Sub New (context As PrincipalContext)
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) |
- 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, System::String ^ samAccountName, System::String ^ password, bool enabled);
public UserPrincipal (System.DirectoryServices.AccountManagement.PrincipalContext context, string samAccountName, string password, bool enabled);
new System.DirectoryServices.AccountManagement.UserPrincipal : System.DirectoryServices.AccountManagement.PrincipalContext * string * string * bool -> System.DirectoryServices.AccountManagement.UserPrincipal
Public Sub New (context As PrincipalContext, samAccountName As String, password As String, enabled As Boolean)
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) |
.NET-tilbakemelding
.NET er et åpen kilde-prosjekt. Velg en kobling for å gi tilbakemelding: