I have an application that requires AD authentication. On top of that, the users usernames are stored in aspnet_users and they are assigned roles, so having a valid domain id is not enough to access the site. It works fine.
For users with valid domain ids who are not part of the system, I am trying to make a "request access" page. So, by the time they login I know their user id. To populate the access request form, I am trying to get the user's information from AD but it is giving me grief! I either get "Logon failure: unknown user name or bad password" or if I remove one of the lines below(deSearch.SearchRoot = de), I get no info for the user (no errors, but no inof either).
private DirectoryEntry GetUserByUserID(string UserID)
DirectoryEntry de = new DirectoryEntry("LDAP://blah.blah.blah");
DirectorySearcher deSearch = new DirectorySearcher();
deSearch.SearchRoot = de; <--- If I remove this line, no error and no data
deSearch.Filter = "(&(objectClass=user)(SAMAccountName=" + UserID + "))";
deSearch.SearchScope = SearchScope.Subtree;
SearchResult results = deSearch.FindOne();
if (!(results == null))
de = new DirectoryEntry(results.Path);
// de = new DirectoryEntry(results.Path, "administrator", "
View Complete Post