1 out of 2 rated this helpful - Rate this topic

PrincipalContext Class

Encapsulates the server or domain against which all operations are performed, the container that is used as the base of those operations, and the credentials used to perform the operations.

System.Object
  System.DirectoryServices.AccountManagement.PrincipalContext

Namespace:  System.DirectoryServices.AccountManagement
Assembly:  System.DirectoryServices.AccountManagement (in System.DirectoryServices.AccountManagement.dll)
[SecurityPermissionAttribute(SecurityAction.Assert, Flags = SecurityPermissionFlag.UnmanagedCode)]
[DirectoryServicesPermissionAttribute(SecurityAction.InheritanceDemand, Unrestricted = true)]
[DirectoryServicesPermissionAttribute(SecurityAction.LinkDemand, Unrestricted = true)]
public class PrincipalContext : IDisposable

The PrincipalContext type exposes the following members.

  Name Description
Public method PrincipalContext(ContextType) Initializes a new instance of the PrincipalContext class with the specified context type.
Public method PrincipalContext(ContextType, String) Initializes a new instance of the PrincipalContext class with the specified context type and name.
Public method PrincipalContext(ContextType, String, String) Initializes a new instance of the PrincipalContext class with the specified context type, name, and container.
Public method PrincipalContext(ContextType, String, String, ContextOptions) Initializes a new instance of the PrincipalContext class with the specified context type, name, container, and context options.
Public method PrincipalContext(ContextType, String, String, String) Initializes a new instance of the PrincipalContext class with the specified context type, name, username, and password.
Public method PrincipalContext(ContextType, String, String, String, String) Initializes a new instance of the PrincipalContext class with the specified context type, name, container, username, and password.
Public method 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.
Top
  Name Description
Public property ConnectedServer Gets the name of the server to which the principal context is connected.
Public property Container Gets the value specified in the container parameter in the constructor.
Public property ContextType Gets the context type that specifies the type of store for the principal context.
Public property Name Gets the value specified as the name parameter in the constructor.
Public property Options Gets the options specified in the contextOptions parameter of the constructor.
Public property UserName Gets the value specified in the username parameter in the constructor.
Top
  Name Description
Public method Dispose Disposes the current instance of the PrincipalContext object.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method ValidateCredentials(String, String) Creates the connections to the server and returns a Boolean value that specifies whether the specified username and password are valid.
Public method ValidateCredentials(String, String, ContextOptions) Creates the connections to the server and returns a Boolean value that specifies whether the specified user name and password are valid. This method performs fast credential validation of the username and password.
Top

For search operations, the principal context defines the search base, and for insert operations the context defines the container into which the object is inserted.

.NET Framework

Supported in: 4, 3.5

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Sample Code
$0        public static PrincipalContext GetPrincipalContext(string sUserName, string sPassword)$0 $0        {$0 $0            PrincipalContext oPrincipalContext = new PrincipalContext$0 $0               (ContextType.Domain, sDomain, sDefaultOU, ContextOptions.SimpleBind,$0 $0               sUserName, sPassword);$0 $0            return oPrincipalContext;$0 $0        }$0 $0 $0        public static PrincipalContext GetPrincipalContext(string sUserName, string sPassword)$0 $0        {$0 $0            PrincipalContext oPrincipalContext = new PrincipalContext$0 $0               (ContextType.Domain, sDomain, sDefaultOU, ContextOptions.SimpleBind,$0 $0               sUserName, sPassword);$0 $0            return oPrincipalContext;$0 $0        }$0 $0