DirectoryContext Class
The DirectoryContext class identifies a specific directory and the credentials that are used to access the directory.
Namespace: System.DirectoryServices.ActiveDirectory
Assembly: System.DirectoryServices (in System.DirectoryServices.dll)
The DirectoryContext type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | DirectoryContext(DirectoryContextType) | Initializes a new instance of the DirectoryContext class of the specified type that contains the credentials of the current user context. |
![]() | DirectoryContext(DirectoryContextType, String) | Initializes a new instance of the DirectoryContext class of the specified type that contains the specified name and the credentials of the current user context. |
![]() | DirectoryContext(DirectoryContextType, String, String) | Initializes a new instance of the DirectoryContext class of the specified type that contains the specified user name and password. |
![]() | DirectoryContext(DirectoryContextType, String, String, String) | Initializes a new instance of the DirectoryContext class of the specified type that contains the specified target, user name, and password. |
| Name | Description | |
|---|---|---|
![]() | ContextType | Gets the type of the context object. |
![]() | Name | Gets the name of the context. |
![]() | UserName | Gets the user name of the context. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified object is equal to the current object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
A directory context must be created before accessing the methods and properties of a System.DirectoryServices.ActiveDirectory directory object such as a domain or forest.
When creating a directory context, the process' current credentials or alternate credentials can be applied to that context by using the appropriate constructor. These credentials determine the permissions that are in effect when the program accesses directory objects. Because Active Directory Domain Services objects might be protected against retrieval or modification by non-administrative users, the use of alternate credentials with permission to access the target objects is sometimes necessary for proper program functionality.
The following table contains a list of the target types that are allowed and a description of the format of the target string.
Target type | DirectoryContextType member | Target name format |
|---|---|---|
Domain Controller | The DNS name of the domain controller. | |
AD LDS Instance | The DNS name of the AD LDS server and the LDAP port number, for example, ad_lds_instance.fabrikam.com:389. | |
Domain | The DNS name of the domain, for example, sales.corp.fabrikam.com. | |
Forest | The DNS name of the forest, for example, corp.fabrikam.com. | |
Application Partition | The DNS name of the application partition. | |
AD LDS Configuration Set | One of the keywords that is associated with the service connection point registered by AD LDS instances for the configuration set. |
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.


