C# – LDAP – Active directory access

Standard
 

               Microsoft technology of distributed directory structure to manage internal data such as profile, policy, security, authentication, network printer, windows server, network user, mail server..etc in centralized location uses by and ties up either few computers within the building or wide network resources span various countries in the global .

              This centralized data uses and integrates with internal organization systems connected and manipulated by various protocols. LDAP (Light Weight Access Protocol) one of protocols widely use to connect the Active directory or Enterprise Directory.

              System.DirectoryServices namespace using to achieve this feature in .NET.

using System;

using System.DirectoryServices;


namespace ActiveDirectory

{

class Program

{

static void Main(string[] args)

{

string strDSNPath = @"LDAP://ldap.myOrg.com:nnn/ou=People,o=myOrg.com";

string strUsername = "LDAPUser";

string strPassword = "ValidPassword";

DirectoryEntry dEntry = new DirectoryEntry(strDSNPath, strUsername, strPassword);

DirectorySearcher dSearcher = new DirectorySearcher(dEntry);

dSearcher.Filter = "modifytimestamp>=20090702000000Z";

//dSearcher.Filter = "|(employeeNumber=123456)";

//dSearcher.Filter = "|(employeeType=TypeOfEmployee)";

//dSearcher.Filter = "(|(mail=my@mycompany.com)(mail=colleague@mycompany.com))";

//dSearcher.Filter = "|(OrganizationSpecificKey=CustamizeValue)";

SearchResultCollection sResultCollection = dSearcher.FindAll();


foreach (SearchResult sResult in sResultCollection)

{

Console.WriteLine(sResult.Properties["givenName"].ToString());

}

dEntry.Close();

}

}

}

 

2nd Querter of year 2005, first time I heared this technology and used this namespace to create small interface to collect the organization employee list with specific role.  

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s