Team LiB
Previous Section Next Section

Connecting and Binding to Active Directory

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.

Code Example: Binding to Active Directory As a Specific User
Start example
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";
                  }
          }
}
End example
Code Example: Binding to Active Directory As the Logged-on User
Start example
using System;
using System.DirectoryServices;
namespace Chapter12
{

          public class DirectoryBinding
          {
                 public DirectoryBinding()
                 {
                        DirectoryEntry MyDirectoryObject =
                           new DirectoryEntry("LDAP://HMSRevenge/rootDSE");
                 }
          }
}
End example

Team LiB
Previous Section Next Section