For simple access, you can use the DirectoryEntry class to create Directory objects that allow you to bind to Active Directory. The following examples demonstrate how to bind to Active Directory as a specific user and how to bind to Active Directory as the logged-on user.
using System;
using System.DirectoryServices;
namespace Chapter12
{
public class DirectoryBinding
{
public DirectoryBinding()
{
DirectoryEntry MyDirectoryObject = new DirectoryEntry();
MyDirectoryObject.Path = "LDAP://HMSRevenge/rootDSE";
MyDirectoryObject.Username = @"Test\gregmcb";
MyDirectoryObject.Password = @"MyPassword";
}
}
}