Upravit

Sdílet prostřednictvím


PrincipalContext Constructors

Definition

Initializes a new instance of the PrincipalContext class.

Overloads

PrincipalContext(ContextType)

Initializes a new instance of the PrincipalContext class with the specified context type.

PrincipalContext(ContextType, String)

Initializes a new instance of the PrincipalContext class with the specified context type and name.

PrincipalContext(ContextType, String, String)

Initializes a new instance of the PrincipalContext class with the specified context type, name, and container.

PrincipalContext(ContextType, String, String, ContextOptions)

Initializes a new instance of the PrincipalContext class with the specified context type, name, container, and context options.

PrincipalContext(ContextType, String, String, String)

Initializes a new instance of the PrincipalContext class with the specified context type, name, username, and password.

PrincipalContext(ContextType, String, String, String, String)

Initializes a new instance of the PrincipalContext class with the specified context type, name, container, username, and password.

PrincipalContext(ContextType, String, String, ContextOptions, String, String)

Initializes a new instance of the PrincipalContext class with the specified context type, name, container, context options, username, and password.

Remarks

The PrincipalContext constructors perform validation of the parameters and server, but not do not attempt to validate credentials.

When the principal context object is created without specifying a container, it may be used to represent multiple distinct containers. One container may be used as the base of query operations, while additional containers can hold newly-created principal objects. For example, when users or groups are inserted into the domain context type, the Account Management API uses the default well-known user container, "CN=Users,DC=Fabrikam,DC=com". When computers are inserted in the store, the API uses the default "CN=Computers,DC=Fabrikam,DC=com" container. Note that the default container names can be changed by the domain administrator. Since the principal object constructors can only specify one principal context, additional contexts are exposed as the default behavior when the application creates a domain context without specifying a container. Since the application directory does not have well-known containers, the application must specify a container in the constructor or the ArgumentException is thrown. Since SAM does not have containers, a ArgumentException is thrown if the application attempts to specify a container in the constructor.

In each version of the constructor that takes a user name as a parameter, the userName string can be in various different formats. The three supported NameFormats for are Nt4Name, UserPrincipalName, and SamAccountName. For more information about name formats, see the ADS_NAME_TYPE_ENUM documentation.

PrincipalContext(ContextType)

Source:
Context.cs
Source:
Context.cs
Source:
Context.cs

Initializes a new instance of the PrincipalContext class with the specified context type.

public:
 PrincipalContext(System::DirectoryServices::AccountManagement::ContextType contextType);
public PrincipalContext (System.DirectoryServices.AccountManagement.ContextType contextType);
new System.DirectoryServices.AccountManagement.PrincipalContext : System.DirectoryServices.AccountManagement.ContextType -> System.DirectoryServices.AccountManagement.PrincipalContext
Public Sub New (contextType As ContextType)

Parameters

contextType
ContextType

A ContextType enumeration value specifying the type of store for the principal context.

Exceptions

A name or container must be specified when using the application directory context.

The contextType parameter does not contain a valid ContextType enumeration value.

Applies to

PrincipalContext(ContextType, String)

Source:
Context.cs
Source:
Context.cs
Source:
Context.cs

Initializes a new instance of the PrincipalContext class with the specified context type and name.

public:
 PrincipalContext(System::DirectoryServices::AccountManagement::ContextType contextType, System::String ^ name);
public PrincipalContext (System.DirectoryServices.AccountManagement.ContextType contextType, string name);
new System.DirectoryServices.AccountManagement.PrincipalContext : System.DirectoryServices.AccountManagement.ContextType * string -> System.DirectoryServices.AccountManagement.PrincipalContext
Public Sub New (contextType As ContextType, name As String)

Parameters

contextType
ContextType

A ContextType enumeration value specifying the type of store for the principal context.

name
String

The name of the domain or server for Domain context types, the machine name for Machine context types, or the name of the server and port hosting the ApplicationDirectory instance.

If the name is null for a Domain context type this context is a domain controller for the domain of the user principal under which the thread is running. If the name is null for a Machine context type, this is the local machine name. This parameter cannot be null for ApplicationDirectory context types.

Exceptions

A name must be specified when ApplicationDirectory is specified in the contextType parameter.

The contextType parameter does not contain a valid ContextType enumeration value.

Applies to

PrincipalContext(ContextType, String, String)

Source:
Context.cs
Source:
Context.cs
Source:
Context.cs

Initializes a new instance of the PrincipalContext class with the specified context type, name, and container.

public:
 PrincipalContext(System::DirectoryServices::AccountManagement::ContextType contextType, System::String ^ name, System::String ^ container);
public PrincipalContext (System.DirectoryServices.AccountManagement.ContextType contextType, string name, string container);
new System.DirectoryServices.AccountManagement.PrincipalContext : System.DirectoryServices.AccountManagement.ContextType * string * string -> System.DirectoryServices.AccountManagement.PrincipalContext
Public Sub New (contextType As ContextType, name As String, container As String)

Parameters

contextType
ContextType

A ContextType enumeration value specifying the type of store for the principal context.

name
String

The name of the domain or server for Domain context types, the machine name for Machine context types, or the name of the server and port hosting the ApplicationDirectory instance.

If the name is null for a Domain context type this context is a domain controller for the domain of the user principal under which the thread is running. If the name is null for a Machine context type, this is the local machine name. This parameter cannot be null for ApplicationDirectory context types.

container
String

The container on the store to use as the root of the context. All queries are performed under this root, and all inserts are performed into this container.

For Domain and ApplicationDirectory context types, this parameter is the distinguished name of a container object.

For Machine context types, this parameter must be set to null.

Exceptions

A container cannot be specified when the Machine context type is specified in the contextType parameter.

A name or container must be specified when ApplicationDirectory is specified in the contextType parameter.

The contextType parameter does not contain a valid ContextType enumeration value.

Remarks

The InvalidOperationException may be thrown in subsequent directory operations calls that connect to the server if the container specified for a Domain principal context is not a valid container. A container is defined as an object whose schema class has the principal classes, either user, group, or computer, in its possibleInferiors attribute.

Applies to

PrincipalContext(ContextType, String, String, ContextOptions)

Source:
Context.cs
Source:
Context.cs
Source:
Context.cs

Initializes a new instance of the PrincipalContext class with the specified context type, name, container, and context options.

public:
 PrincipalContext(System::DirectoryServices::AccountManagement::ContextType contextType, System::String ^ name, System::String ^ container, System::DirectoryServices::AccountManagement::ContextOptions options);
public PrincipalContext (System.DirectoryServices.AccountManagement.ContextType contextType, string name, string container, System.DirectoryServices.AccountManagement.ContextOptions options);
new System.DirectoryServices.AccountManagement.PrincipalContext : System.DirectoryServices.AccountManagement.ContextType * string * string * System.DirectoryServices.AccountManagement.ContextOptions -> System.DirectoryServices.AccountManagement.PrincipalContext
Public Sub New (contextType As ContextType, name As String, container As String, options As ContextOptions)

Parameters

contextType
ContextType

A ContextType enumeration value specifying the type of store for the principal context.

name
String

The name of the domain or server for Domain context types, the machine name for Machine context types, or the name of the server and port hosting the ApplicationDirectory instance.

If the name is null for a Domain context type this context is a domain controller for the domain of the user principal under which the thread is running. If the name is null for a Machine context type, this is the local machine name. This parameter cannot be null for ApplicationDirectory context types.

container
String

The container on the store to use as the root of the context. All queries are performed under this root, and all inserts are performed into this container.

For Domain and ApplicationDirectory context types, this parameter is the distinguished name of a container object.

For Machine context types, this parameter must be set to null.

options
ContextOptions

A combination of one or more ContextOptions enumeration values specifying the options used to bind to the server. If this parameter is null, the default options are ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing.

Exceptions

A container cannot be specified when the Machine context type is specified in the contextType parameter.

A name or container must be specified when ApplicationDirectory is specified in the contextType parameter.

The contextType parameter does not contain a valid ContextType enumeration value.

The options parameter does not contain a combination of valid ContextOptions enumeration values.

Remarks

The InvalidOperationException may be thrown in subsequent directory operations calls that connect to the server if the container specified for a Domain principal context is not a valid container. A container is defined as an object whose schema class has the principal classes, either user, group, or computer, in its possibleInferiors attribute.

Applies to

PrincipalContext(ContextType, String, String, String)

Source:
Context.cs
Source:
Context.cs
Source:
Context.cs

Initializes a new instance of the PrincipalContext class with the specified context type, name, username, and password.

public:
 PrincipalContext(System::DirectoryServices::AccountManagement::ContextType contextType, System::String ^ name, System::String ^ userName, System::String ^ password);
public PrincipalContext (System.DirectoryServices.AccountManagement.ContextType contextType, string name, string userName, string password);
new System.DirectoryServices.AccountManagement.PrincipalContext : System.DirectoryServices.AccountManagement.ContextType * string * string * string -> System.DirectoryServices.AccountManagement.PrincipalContext
Public Sub New (contextType As ContextType, name As String, userName As String, password As String)

Parameters

contextType
ContextType

A ContextType enumeration value specifying the type of store for the principal context.

name
String

The name of the domain or server for Domain context types, the machine name for Machine context types, or the name of the server and port hosting the ApplicationDirectory instance.

If the name is null for a Domain context type this context is a domain controller for the domain of the user principal under which the thread is running. If the name is null for a Machine context type, this is the local machine name. This parameter cannot be null for ApplicationDirectory context types.

userName
String

The username used to connect to the store. If the userName and password parameters are both null, the credentials of the current process are used. Otherwise, both userName and password must be non-null, and the credentials they specify are used to connect to the store.

password
String

The password used to connect to the store. If the userName and password parameters are both null, the credentials of the current process are used. Otherwise, both userName and password must be non-null, and the credentials they specify are used to connect to the store.

Exceptions

The username and password parameters must either be null or contain a value.

A name must be specified when ApplicationDirectory is specified in the contextType parameter.

The contextType parameter does not contain a valid ContextType enumeration value.

Applies to

PrincipalContext(ContextType, String, String, String, String)

Source:
Context.cs
Source:
Context.cs
Source:
Context.cs

Initializes a new instance of the PrincipalContext class with the specified context type, name, container, username, and password.

public:
 PrincipalContext(System::DirectoryServices::AccountManagement::ContextType contextType, System::String ^ name, System::String ^ container, System::String ^ userName, System::String ^ password);
public PrincipalContext (System.DirectoryServices.AccountManagement.ContextType contextType, string name, string container, string userName, string password);
new System.DirectoryServices.AccountManagement.PrincipalContext : System.DirectoryServices.AccountManagement.ContextType * string * string * string * string -> System.DirectoryServices.AccountManagement.PrincipalContext
Public Sub New (contextType As ContextType, name As String, container As String, userName As String, password As String)

Parameters

contextType
ContextType

A ContextType enumeration value specifying the type of store for the principal context.

name
String

The name of the domain or server for Domain context types, the machine name for Machine context types, or the name of the server and port hosting the ApplicationDirectory instance.

If the name is null for a Domain context type this context is a domain controller for the domain of the user principal under which the thread is running. If the name is null for a Machine context type, this is the local machine name. This parameter cannot be null for ApplicationDirectory context types.

container
String

The container on the store to use as the root of the context. All queries are performed under this root, and all inserts are performed into this container.

For Domain and ApplicationDirectory context types, this parameter is the distinguished name of a container object.

For Machine context types, this parameter must be set to null.

userName
String

The username used to connect to the store. If the userName and password parameters are both null, the default credentials of the current principal are used. Otherwise, both userName and password must be non-null, and the credentials they specify are used to connect to the store.

password
String

The password used to connect to the store. If the userName and password parameters are both null, the default credentials of the current principal are used. Otherwise, both userName and password must be non-null, and the credentials they specify are used to connect to the store.

Exceptions

The username and password parameters must either be null or contain a value.

A container cannot be specified when the Machine context type is specified in the contextType parameter.

A name or container must be specified when ApplicationDirectory is specified in the contextType parameter.

The contextType parameter does not contain a valid ContextType enumeration value.

Remarks

The InvalidOperationException may be thrown in subsequent directory operations calls that connect to the server if the container specified for a Domain principal context is not a valid container. A container is defined as an object whose schema class has the principal classes, either user, group, or computer, in its possibleInferiors attribute.

Applies to

PrincipalContext(ContextType, String, String, ContextOptions, String, String)

Source:
Context.cs
Source:
Context.cs
Source:
Context.cs

Initializes a new instance of the PrincipalContext class with the specified context type, name, container, context options, username, and password.

public:
 PrincipalContext(System::DirectoryServices::AccountManagement::ContextType contextType, System::String ^ name, System::String ^ container, System::DirectoryServices::AccountManagement::ContextOptions options, System::String ^ userName, System::String ^ password);
public PrincipalContext (System.DirectoryServices.AccountManagement.ContextType contextType, string name, string container, System.DirectoryServices.AccountManagement.ContextOptions options, string userName, string password);
new System.DirectoryServices.AccountManagement.PrincipalContext : System.DirectoryServices.AccountManagement.ContextType * string * string * System.DirectoryServices.AccountManagement.ContextOptions * string * string -> System.DirectoryServices.AccountManagement.PrincipalContext
Public Sub New (contextType As ContextType, name As String, container As String, options As ContextOptions, userName As String, password As String)

Parameters

contextType
ContextType

A ContextType enumeration value specifying the type of store for the principal context.

name
String

The name of the domain or server for Domain context types, the machine name for Machine context types, or the name of the server and port hosting the ApplicationDirectory instance.

If the name is null for a Domain context type this context is a domain controller for the domain of the user principal under which the thread is running. If the name is null for a Machine context type, this is the local machine name. This parameter cannot be null for ApplicationDirectory context types.

container
String

The container on the store to use as the root of the context. All queries are performed under this root, and all inserts are performed into this container.

For Domain and ApplicationDirectory context types, this parameter is the distinguished name of a container object.

For Machine context types, this parameter must be set to null.

options
ContextOptions

A combination of one or more ContextOptions enumeration values the options used to bind to the server. If this parameter is null, the default options are ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing.

userName
String

The username used to connect to the store. If the userName and password parameters are both null, the default credentials of the current principal are used. Otherwise, both userName and password must be non-null, and the credentials they specify are used to connect to the store.

password
String

The password used to connect to the store. If the userName and password parameters are both null, the default credentials of the current principal are used. Otherwise, both userName and password must be non-null, and the credentials they specify are used to connect to the store.

Exceptions

The username and password parameters must either be null or contain a value.

A container cannot be specified when the Machine context type is specified in the contextType parameter.

A name or container must be specified when ApplicationDirectory is specified in the contextType parameter.

The contextType parameter does not contain a valid ContextType enumeration value.

The options parameter does not contain a combination of valid ContextOptions enumeration values.

Remarks

The InvalidOperationException may be thrown in subsequent directory operations calls that connect to the server if the container specified for a Domain principal context is not a valid container. A container is defined as an object whose schema class has the principal classes, either user, group, or computer, in its possibleInferiors attribute.

Applies to