Connecting Active Directory
Active Directory - AD
----
Paramters for connecting the AD
adConnectionString = “LDAP://SERVERNAME.DOMAIN1.COM:PORTNUMBER"
Domain name :domain1
Service Account :the Account available in the AD server authenticated to connect AD
Password : Password for that service account
DirectoryEntry object is used for connecting the AD.
DirectorySearcher object is used for fetching the entry from the AD.
DirectoryEntry objDirectoryEntry = new DirectoryEntry(adConnectionString, Domain name + "\\" + ServiceAccount, Password, AuthenticationTypes.Secure);
DirectorySearcher objDirectorySearcher = new DirectorySearcher(objDirectoryEntry);
SearchResult objSearchResult;
The below code will be used to filter and fetch the data from the AD.Thje filter will be used to filter the specific Organizational Unit, or a specific User, or a group
We can fetch all the data in a method FindAll.We can also fetch the indivdual user using another method called FindOne of the DirectorySearcher object.
The results fetched are assigned to another object called searchresult.
This will return null if we are not able to fetch data from the AD
objDirectorySearcher.PageSize = 1;
objDirectorySearcher.Filter = "(objectClass=*)";
objSearchResult = objDirectorySearcher.FindAll();
if (objSearchResult != null)
{
}