Hi all,
I have the following code to read user information (email address) from Active Directory in ASP.net. However, I'm getting this error message: System.Runtime.InteropServices.COMException: The server is not operational. Has anybody gotten the same error? I need your help.
string filter = string.Format("(&ObjectClass={0}) (sAMAccountName={1}))", "person", principal);
string domain = "DOMAIN";
string[] properties = new string[] { "fullname" };
DirectoryEntry adRoot = new DirectoryEntry("LDAP://" + domain, null, null, AuthenticationTypes.Secure);
DirectorySearcher searcher = new DirectorySearcher(adRoot);
searcher.SearchScope= SearchScope.Subtree;
searcher.ReferralChasing= ReferralChasingOption.All;
searcher.PropertiesToLoad.AddRange(properties);
searcher.Filter= filter;
SearchResult result = searcher.FindOne();
DirectoryEntry directoryEntry = result.GetDirectoryEntry();
string displayName = directoryEntry.Properties["displayName"][0].ToString();
string email = directoryEntry.Properties["mail"][0].ToString();
Label1.Text= displayName;
Label2.Text = email;
}
Thanks,
A.
I have the following code to read user information (email address) from Active Directory in ASP.net. However, I'm getting this error message: System.Runtime.InteropServices.COMException: The server is not operational. Has anybody gotten the same error? I need your help.
string filter = string.Format("(&ObjectClass={0}) (sAMAccountName={1}))", "person", principal);
string domain = "DOMAIN";
string[] properties = new string[] { "fullname" };
DirectoryEntry adRoot = new DirectoryEntry("LDAP://" + domain, null, null, AuthenticationTypes.Secure);
DirectorySearcher searcher = new DirectorySearcher(adRoot);
searcher.SearchScope= SearchScope.Subtree;
searcher.ReferralChasing= ReferralChasingOption.All;
searcher.PropertiesToLoad.AddRange(properties);
searcher.Filter= filter;
SearchResult result = searcher.FindOne();
DirectoryEntry directoryEntry = result.GetDirectoryEntry();
string displayName = directoryEntry.Properties["displayName"][0].ToString();
string email = directoryEntry.Properties["mail"][0].ToString();
Label1.Text= displayName;
Label2.Text = email;
}
Thanks,
A.