PrincipalContext 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 PrincipalContext 类的新实例。
重载
| 名称 | 说明 |
|---|---|
| PrincipalContext(ContextType) |
使用指定的上下文类型初始化类的新实例 PrincipalContext 。 |
| PrincipalContext(ContextType, String) |
使用指定的上下文类型和名称初始化类的新实例 PrincipalContext 。 |
| PrincipalContext(ContextType, String, String) |
使用指定的上下文类型、名称和容器初始化类的新实例 PrincipalContext 。 |
| PrincipalContext(ContextType, String, String, ContextOptions) |
使用指定的上下文类型、名称、容器和上下文选项初始化类的新实例 PrincipalContext 。 |
| PrincipalContext(ContextType, String, String, String) |
使用指定的上下文类型、名称、用户名和密码初始化类的新实例 PrincipalContext 。 |
| PrincipalContext(ContextType, String, String, String, String) |
使用指定的上下文类型、名称、容器、用户名和密码初始化类的新实例 PrincipalContext 。 |
| PrincipalContext(ContextType, String, String, ContextOptions, String, String) |
使用指定的上下文类型、名称、容器、上下文选项、用户名和密码初始化类的新实例 PrincipalContext 。 |
注解
PrincipalContext构造函数对参数和服务器执行验证,但不尝试验证凭据。
在不指定容器的情况下创建主体上下文对象时,它可用于表示多个不同的容器。 一个容器可用作查询操作的基数,而其他容器可以保存新创建的主体对象。 例如,当用户或组插入域上下文类型时,帐户管理 API 使用默认的已知用户容器“CN=Users,DC=Fabrikam,DC=com”。 在存储中插入计算机时,API 使用默认的“CN=Computers,DC=Fabrikam,DC=com”容器。 请注意,域管理员可以更改默认容器名称。 由于主体对象构造函数只能指定一个主体上下文,因此当应用程序创建域上下文而不指定容器时,其他上下文将公开为默认行为。 由于应用程序目录没有已知的容器,因此应用程序必须在构造函数中指定容器或 ArgumentException 引发容器。 由于 SAM 没有容器,因此如果应用程序尝试在构造函数中指定容器,则会引发 a ArgumentException 。
在采用用户名作为参数的每个构造函数版本中, userName 字符串可以采用不同的格式。 支持的三个 NameFormats 为 Nt4Name、UserPrincipalName 和 SamAccountName。 有关名称格式的详细信息,请参阅 ADS_NAME_TYPE_ENUM文档。
PrincipalContext(ContextType)
使用指定的上下文类型初始化类的新实例 PrincipalContext 。
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)
参数
- contextType
- ContextType
一个 ContextType 枚举值,该值指定主体上下文的存储类型。
例外
使用应用程序目录上下文时,必须指定名称或容器。
该 contextType 参数不包含有效的 ContextType 枚举值。
适用于
PrincipalContext(ContextType, String)
使用指定的上下文类型和名称初始化类的新实例 PrincipalContext 。
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)
参数
- contextType
- ContextType
一个 ContextType 枚举值,该值指定主体上下文的存储类型。
- name
- String
上下文类型的域或服务器 Domain 的名称、上下文类型的计算机名称 Machine 或托管 ApplicationDirectory 实例的服务器和端口的名称。
如果该名称用于nullDomain上下文类型,则此上下文是运行线程的用户主体域的域控制器。 如果名称用于nullMachine上下文类型,则这是本地计算机名称。 此参数不能 null 用于 ApplicationDirectory 上下文类型。
例外
必须在参数中指定的contextType时间ApplicationDirectory指定名称。
该 contextType 参数不包含有效的 ContextType 枚举值。
适用于
PrincipalContext(ContextType, String, String)
使用指定的上下文类型、名称和容器初始化类的新实例 PrincipalContext 。
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)
参数
- contextType
- ContextType
一个 ContextType 枚举值,该值指定主体上下文的存储类型。
- name
- String
上下文类型的域或服务器 Domain 的名称、上下文类型的计算机名称 Machine 或托管 ApplicationDirectory 实例的服务器和端口的名称。
如果该名称用于nullDomain上下文类型,则此上下文是运行线程的用户主体域的域控制器。 如果名称用于nullMachine上下文类型,则这是本地计算机名称。 此参数不能 null 用于 ApplicationDirectory 上下文类型。
- container
- String
要用作上下文根的存储区上的容器。 所有查询都在此根目录下执行,所有插入都执行到此容器中。
对于 Domain 和 ApplicationDirectory 上下文类型,此参数是容器对象的可分辨名称。
对于 Machine 上下文类型,此参数必须设置为 null。
例外
在参数中contextType指定上下文类型时Machine,不能指定容器。
在参数中contextType指定名称或容器时ApplicationDirectory,必须指定名称或容器。
该 contextType 参数不包含有效的 ContextType 枚举值。
注解
InvalidOperationException如果为Domain主体上下文指定的容器不是有效的容器,则可能会在后续的目录操作调用中引发该调用,这些调用连接到服务器。 容器定义为一个对象,其架构类在其可能的Inferiors 属性中具有主体类(用户、组或计算机)。
适用于
PrincipalContext(ContextType, String, String, ContextOptions)
使用指定的上下文类型、名称、容器和上下文选项初始化类的新实例 PrincipalContext 。
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)
参数
- contextType
- ContextType
一个 ContextType 枚举值,该值指定主体上下文的存储类型。
- name
- String
上下文类型的域或服务器 Domain 的名称、上下文类型的计算机名称 Machine 或托管 ApplicationDirectory 实例的服务器和端口的名称。
如果该名称用于nullDomain上下文类型,则此上下文是运行线程的用户主体域的域控制器。 如果名称用于nullMachine上下文类型,则这是本地计算机名称。 此参数不能 null 用于 ApplicationDirectory 上下文类型。
- container
- String
要用作上下文根的存储区上的容器。 所有查询都在此根目录下执行,所有插入都执行到此容器中。
对于 Domain 和 ApplicationDirectory 上下文类型,此参数是容器对象的可分辨名称。
对于 Machine 上下文类型,此参数必须设置为 null。
- options
- ContextOptions
一个或多个 ContextOptions 枚举值的组合,指定用于绑定到服务器的选项。 如果此参数为 null,则默认选项为 ContextOptions.Negotiate |ContextOptions.Signing |ContextOptions.Sealing。
例外
在参数中contextType指定上下文类型时Machine,不能指定容器。
在参数中contextType指定名称或容器时ApplicationDirectory,必须指定名称或容器。
该 contextType 参数不包含有效的 ContextType 枚举值。
该 options 参数不包含有效 ContextOptions 枚举值的组合。
注解
InvalidOperationException如果为Domain主体上下文指定的容器不是有效的容器,则可能会在后续的目录操作调用中引发该调用,这些调用连接到服务器。 容器定义为一个对象,其架构类在其可能的Inferiors 属性中具有主体类(用户、组或计算机)。
适用于
PrincipalContext(ContextType, String, String, String)
使用指定的上下文类型、名称、用户名和密码初始化类的新实例 PrincipalContext 。
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)
参数
- contextType
- ContextType
一个 ContextType 枚举值,该值指定主体上下文的存储类型。
- name
- String
上下文类型的域或服务器 Domain 的名称、上下文类型的计算机名称 Machine 或托管 ApplicationDirectory 实例的服务器和端口的名称。
如果该名称用于nullDomain上下文类型,则此上下文是运行线程的用户主体域的域控制器。 如果名称用于nullMachine上下文类型,则这是本地计算机名称。 此参数不能 null 用于 ApplicationDirectory 上下文类型。
- userName
- String
用于连接到存储的用户名。
userName如果这两个参数password都是null,则使用当前进程的凭据。 否则,两者userNamepassword都必须为非 null,并且它们指定的凭据用于连接到存储区。
- password
- String
用于连接到存储区的密码。
userName如果这两个参数password都是null,则使用当前进程的凭据。 否则,两者userNamepassword都必须为非 null,并且它们指定的凭据用于连接到存储区。
例外
该 contextType 参数不包含有效的 ContextType 枚举值。
适用于
PrincipalContext(ContextType, String, String, String, String)
使用指定的上下文类型、名称、容器、用户名和密码初始化类的新实例 PrincipalContext 。
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)
参数
- contextType
- ContextType
一个 ContextType 枚举值,该值指定主体上下文的存储类型。
- name
- String
上下文类型的域或服务器 Domain 的名称、上下文类型的计算机名称 Machine 或托管 ApplicationDirectory 实例的服务器和端口的名称。
如果该名称用于nullDomain上下文类型,则此上下文是运行线程的用户主体域的域控制器。 如果名称用于nullMachine上下文类型,则这是本地计算机名称。 此参数不能 null 用于 ApplicationDirectory 上下文类型。
- container
- String
要用作上下文根的存储区上的容器。 所有查询都在此根目录下执行,所有插入都执行到此容器中。
对于 Domain 和 ApplicationDirectory 上下文类型,此参数是容器对象的可分辨名称。
对于 Machine 上下文类型,此参数必须设置为 null。
- userName
- String
用于连接到存储的用户名。
userName如果两者都具有null参数password,则使用当前主体的默认凭据。 否则,两者userNamepassword都必须为非 null,并且它们指定的凭据用于连接到存储区。
- password
- String
用于连接到存储区的密码。
userName如果两者都具有null参数password,则使用当前主体的默认凭据。 否则,两者userNamepassword都必须为非 null,并且它们指定的凭据用于连接到存储区。
例外
参数userNamepassword必须是null或包含值。
在参数中contextType指定上下文类型时Machine,不能指定容器。
container在参数中contextType指定时ApplicationDirectory,必须指定或name必须指定。
该 contextType 参数不包含有效的 ContextType 枚举值。
注解
InvalidOperationException如果为Domain主体上下文指定的容器不是有效的容器,则可能会在后续的目录操作调用中引发该调用,这些调用连接到服务器。 容器定义为一个对象,其架构类在其可能的Inferiors 属性中具有主体类(用户、组或计算机)。
适用于
PrincipalContext(ContextType, String, String, ContextOptions, String, String)
使用指定的上下文类型、名称、容器、上下文选项、用户名和密码初始化类的新实例 PrincipalContext 。
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)
参数
- contextType
- ContextType
一个 ContextType 枚举值,该值指定主体上下文的存储类型。
- name
- String
上下文类型的域或服务器 Domain 的名称、上下文类型的计算机名称 Machine 或托管 ApplicationDirectory 实例的服务器和端口的名称。
如果该名称用于nullDomain上下文类型,则此上下文是运行线程的用户主体域的域控制器。 如果名称用于nullMachine上下文类型,则这是本地计算机名称。 此参数不能 null 用于 ApplicationDirectory 上下文类型。
- container
- String
要用作上下文根的存储区上的容器。 所有查询都在此根目录下执行,所有插入都执行到此容器中。
对于 Domain 和 ApplicationDirectory 上下文类型,此参数是容器对象的可分辨名称。
对于 Machine 上下文类型,此参数必须设置为 null。
- options
- ContextOptions
一个或多个 ContextOptions 枚举值的组合,这些值用于绑定到服务器的选项。 如果此参数为 null,则默认选项为 ContextOptions.Negotiate |ContextOptions.Signing |ContextOptions.Sealing。
- userName
- String
用于连接到存储的用户名。
userName如果两者都具有null参数password,则使用当前主体的默认凭据。 否则,两者userNamepassword都必须为非 null,并且它们指定的凭据用于连接到存储区。
- password
- String
用于连接到存储区的密码。
userName如果两者都具有null参数password,则使用当前主体的默认凭据。 否则,两者userNamepassword都必须为非 null,并且它们指定的凭据用于连接到存储区。
例外
参数userNamepassword必须是null或包含值。
在参数中contextType指定上下文类型时Machine,不能指定容器。
在参数中contextType指定名称或容器时ApplicationDirectory,必须指定名称或容器。
该 contextType 参数不包含有效的 ContextType 枚举值。
该 options 参数不包含有效 ContextOptions 枚举值的组合。
注解
InvalidOperationException如果为Domain主体上下文指定的容器不是有效的容器,则可能会在后续的目录操作调用中引发该调用,这些调用连接到服务器。 容器定义为一个对象,其架构类在其可能的Inferiors 属性中具有主体类(用户、组或计算机)。