Click here to Skip to main content
15,849,594 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I've built an asp.net project which can get the ActiveDirectory user's data .

I had 4 values to get the information :
1.username
2.password
3.DomainName
4.DomainExtension(like com,local,..)
and the company's computers are under WORKGROUP and they just connect to AD server to get the user's info.


this is my code for getting info:

try

{


String Path = "LDAP:// " + DomainName + "." + DomainExt + "/DC=" + DomainName + ",DC=" + DomainExt;

DirectoryEntry Entry = new DirectoryEntry(Path, DomainName + @"\" + Username, Password);
DirectorySearcher search = new DirectorySearcher(Entry);
search.Filter = String.Format("(SAMAccountName={0})", Username);
search.PropertiesToLoad.Add("sn");
SearchResult result = search.FindOne();



Value = (string)result.Properties["sn"][0];

}


catch (Exception ex)
{
return ex.Message;
}




And I've done this successfully at my office local network ... but when I tested it at the company I've got this error :
Logon failure: unknown user name or bad password.
on this <<SearchResult result = search.FindOne();>>
and they can get the user's info with this username and password with some other program .. so there isn't anything wrong with the username and password ..
and I really don't know how to fix it ...
Posted
Updated 5-Dec-14 21:51pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900