jeudi 26 mars 2015

LDAP query not working in custom web part



I have a custom web part which will pull Active directories custom attribute(logged in user). For testing purpose currently I am trying to get "mail" of currently logged in user. But it is not working. Here is my code



DirectoryEntry entry = new DirectoryEntry("LDAP://rp.fs.asdf.org");
DirectorySearcher mySearcher = new DirectorySearcher(entry, "(sAMAccountName=myuserid1)", new string[] { "mail" });
mySearcher.PropertiesToLoad.Add("mail");
SearchResult result = mySearcher.FindOne();
if (result != null)
{
mailID = result.GetDirectoryEntry().Properties["mail"].Value.ToString();
}
entry.Close();
entry.Dispose();
mySearcher.Dispose();


The same code works perfectly in "Windows form". I have been fighting with this code. Please suggest some ideas. Appreciate your help.








0 commentaires:

Enregistrer un commentaire