Hi All,
I'm trying to connect active directory to asp.net web application made in C# using Visual Web Developer.I'm not sure whether i'm going on the righ track, since its my new research on Active directory connection, please check my code. i'm trying to establish connection to active directory and get the user details.....please recorrect me if i'm wrong.. The code i used to connect to the LDAP is ass below(it says bad url......)
DirectoryEntry rootEntry = new DirectoryEntry();
rootEntry .Path ="ldap://000.000.000.00:000/CN=Users,OU=Role-Based,OU=North America,DC=ca,DC=com";
rootEntry .Username ="DN=CN=GetPaid,OU=Role-Based,OU=North America,DC=ca,DC=com";
rootEntry.Password ="aaaaaaaa";
DirectorySearcher search = new DirectorySearcher(rootEntry);
search .SearchRoot =rootEntry ;
string username="abcdef";
//searcher .Filter ="(&(objectClass=user) (cn=" + UserName +"))";
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if(result ==null)
Response.Write("false");
else
Response.Write("true");