PrincipalContext 建構函式

定義

初始化 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 沒有容器,因此如果應用程式嘗試在建構函式中指定容器, ArgumentException 則會擲回 。

在每個採用使用者名稱作為參數的建構函式版本中, userName 字串可以採用各種不同的格式。 的三個支援的 NameFormats 為 Nt4Name、UserPrincipalName 和 SamAccountName。 如需名稱格式的詳細資訊,請參閱 ADS_NAME_TYPE_ENUM檔

PrincipalContext(ContextType)

來源:
Context.cs
來源:
Context.cs
來源:
Context.cs

使用指定的內容型別,初始化 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)

來源:
Context.cs
來源:
Context.cs
來源:
Context.cs

使用指定的內容型別和名稱,初始化 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 執行個體的伺服器和通訊埠之名稱。

Domain 內容類型的名稱為 null,則此內容為使用者主體網域的網域控制站,執行緒會在這個網域下執行。 若 Machine 內容類型的名稱為 null,則此為本機電腦名稱。 ApplicationDirectory 內容類型的此參數不能為 null

例外狀況

ApplicationDirectory 指定於 contextType 參數中時,必須指定名稱。

contextType 參數不包含有效的 ContextType 列舉值。

適用於

PrincipalContext(ContextType, String, String)

來源:
Context.cs
來源:
Context.cs
來源:
Context.cs

使用指定的內容型別、名稱和容器,初始化 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 執行個體的伺服器和通訊埠之名稱。

Domain 內容類型的名稱為 null,則此內容為使用者主體網域的網域控制站,執行緒會在這個網域下執行。 若 Machine 內容類型的名稱為 null,則此為本機電腦名稱。 ApplicationDirectory 內容類型的此參數不能為 null

container
String

存放區上的容器,當做內容的根項目使用。 所有查詢都在此根目錄下執行,而所有插入都在此容器中執行。

對於 DomainApplicationDirectory 內容型別,這個參數是容器物件的辨別名稱。

針對 Machine 內容類型,此參數必須設為 null

例外狀況

Machine 內容型別指定於 contextType 參數中時,無法指定容器。

ApplicationDirectory 指定於 contextType 參數中時,必須指定名稱或容器。

contextType 參數不包含有效的 ContextType 列舉值。

備註

InvalidOperationException如果為Domain主體內容指定的容器不是有效的容器,則可能會在後續的目錄作業呼叫中擲回 ,以連接到伺服器。 容器定義為物件,其架構類別在其 possibleInferiors 屬性中具有主體類別、使用者、群組或計算機。

適用於

PrincipalContext(ContextType, String, String, ContextOptions)

來源:
Context.cs
來源:
Context.cs
來源:
Context.cs

使用指定的內容型別、名稱、容器和內容選項,初始化 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 執行個體的伺服器和通訊埠之名稱。

Domain 內容類型的名稱為 null,則此內容為使用者主體網域的網域控制站,執行緒會在這個網域下執行。 若 Machine 內容類型的名稱為 null,則此為本機電腦名稱。 ApplicationDirectory 內容類型的此參數不能為 null

container
String

存放區上的容器,當做內容的根項目使用。 所有查詢都在此根目錄下執行,而所有插入都在此容器中執行。

對於 DomainApplicationDirectory 內容型別,這個參數是容器物件的辨別名稱。

針對 Machine 內容類型,此參數必須設為 null

options
ContextOptions

一個或多個 ContextOptions 列舉值的組合,指定用以繫結至伺服器的選項。 若此參數為 null,則預設選項為 ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing。

例外狀況

Machine 內容型別指定於 contextType 參數中時,無法指定容器。

ApplicationDirectory 指定於 contextType 參數中時,必須指定名稱或容器。

contextType 參數不包含有效的 ContextType 列舉值。

options 參數不包含有效 ContextOptions 列舉值的組合。

備註

InvalidOperationException如果為Domain主體內容指定的容器不是有效的容器,則可能會在後續的目錄作業呼叫中擲回 ,以連接到伺服器。 容器定義為物件,其架構類別在其 possibleInferiors 屬性中具有主體類別、使用者、群組或計算機。

適用於

PrincipalContext(ContextType, String, String, String)

來源:
Context.cs
來源:
Context.cs
來源:
Context.cs

使用指定的內容型別、名稱、使用者名稱和密碼,初始化 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 執行個體的伺服器和通訊埠之名稱。

Domain 內容類型的名稱為 null,則此內容為使用者主體網域的網域控制站,執行緒會在這個網域下執行。 若 Machine 內容類型的名稱為 null,則此為本機電腦名稱。 ApplicationDirectory 內容類型的此參數不能為 null

userName
String

用來連接至存放區的使用者名稱。 若 userNamepassword 參數都是 null,則會使用目前處理序的認證。 否則,userNamepassword 必須為非 null,並使用它們指定的認證以連接存放區。

password
String

用來連接遠端存放區的密碼。 若 userNamepassword 參數都是 null,則會使用目前處理序的認證。 否則,userNamepassword 必須為非 null,並使用它們指定的認證以連接存放區。

例外狀況

usernamepassword 參數必須為 null,或包含值。

ApplicationDirectory 指定於 contextType 參數中時,必須指定名稱。

contextType 參數不包含有效的 ContextType 列舉值。

適用於

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

來源:
Context.cs
來源:
Context.cs
來源:
Context.cs

使用指定的內容型別、名稱、容器、使用者名稱和密碼,初始化 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 執行個體的伺服器和通訊埠之名稱。

Domain 內容類型的名稱為 null,則此內容為使用者主體網域的網域控制站,執行緒會在這個網域下執行。 若 Machine 內容類型的名稱為 null,則此為本機電腦名稱。 ApplicationDirectory 內容類型的此參數不能為 null

container
String

存放區上的容器,當做內容的根項目使用。 所有查詢都在此根目錄下執行,而所有插入都在此容器中執行。

對於 DomainApplicationDirectory 內容型別,這個參數是容器物件的辨別名稱。

針對 Machine 內容類型,此參數必須設為 null

userName
String

用來連接至存放區的使用者名稱。 若 userNamepassword 參數都是 null,則會使用目前主體的預設認證。 否則,userNamepassword 必須為非 null,並使用它們指定的認證以連接存放區。

password
String

用來連接遠端存放區的密碼。 若 userNamepassword 參數都是 null,則會使用目前主體的預設認證。 否則,userNamepassword 必須為非 null,並使用它們指定的認證以連接存放區。

例外狀況

usernamepassword 參數必須為 null,或包含值。

Machine 內容型別指定於 contextType 參數中時,無法指定容器。

ApplicationDirectory 指定於 name 參數中時,必須指定 containercontextType

contextType 參數不包含有效的 ContextType 列舉值。

備註

InvalidOperationException如果為Domain主體內容指定的容器不是有效的容器,則可能會在後續的目錄作業呼叫中擲回 ,以連接到伺服器。 容器定義為物件,其架構類別在其 possibleInferiors 屬性中具有主體類別、使用者、群組或計算機。

適用於

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

來源:
Context.cs
來源:
Context.cs
來源:
Context.cs

使用指定的內容型別、名稱、容器、內容選項、使用者名稱和密碼,初始化 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 執行個體的伺服器和通訊埠之名稱。

Domain 內容類型的名稱為 null,則此內容為使用者主體網域的網域控制站,執行緒會在這個網域下執行。 若 Machine 內容類型的名稱為 null,則此為本機電腦名稱。 ApplicationDirectory 內容類型的此參數不能為 null

container
String

存放區上的容器,當做內容的根項目使用。 所有查詢都在此根目錄下執行,而所有插入都在此容器中執行。

對於 DomainApplicationDirectory 內容型別,這個參數是容器物件的辨別名稱。

針對 Machine 內容類型,此參數必須設為 null

options
ContextOptions

一個或多個 ContextOptions 列舉值的組合,供選項用來繫結至伺服器。 若此參數為 null,則預設選項為 ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing。

userName
String

用來連接至存放區的使用者名稱。 若 userNamepassword 參數都是 null,則會使用目前主體的預設認證。 否則,userNamepassword 必須為非 null,並使用它們指定的認證以連接存放區。

password
String

用來連接遠端存放區的密碼。 若 userNamepassword 參數都是 null,則會使用目前主體的預設認證。 否則,userNamepassword 必須為非 null,並使用它們指定的認證以連接存放區。

例外狀況

usernamepassword 參數必須為 null,或包含值。

Machine 內容型別指定於 contextType 參數中時,無法指定容器。

ApplicationDirectory 指定於 contextType 參數中時,必須指定名稱或容器。

contextType 參數不包含有效的 ContextType 列舉值。

options 參數不包含有效 ContextOptions 列舉值的組合。

備註

InvalidOperationException如果為Domain主體內容指定的容器不是有效的容器,則可能會在後續的目錄作業呼叫中擲回連線到伺服器的 。 容器定義為物件,其架構類別在其 possibleInferiors 屬性中具有主體類別、使用者、群組或計算機。

適用於