string principal = this.Context.User.Identity.Name;
string filter = string.Format("(&(ObjectClass={0})(sAMAccountName={1}))", "person", principal);
string domain = "DC=ca,DC=com"; 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 firstName = directoryEntry.Properties["givenName"][0].ToString();
string lastName = directoryEntry.Properties["sn"][0].ToString();
string email = directoryEntry.Properties["mail"][0].ToString();
When I run the page in VS I get the following error in Internet Explorer:
System.Runtime.InteropServices.COMException: Unknown error (0x80005000)
This occurs at the line:
SearchResult result = searcher.FindOne();
Any ideas as to why I am getting the error?
Thanks
Gary
Jiteendra SampathiraoPosted Jun 18, 2011, 1:10 AM
Refer these links:
http://social.msdn.microsoft.com/Forums/en/netfx64bit/thread/6078be16-0d1a-4d6a-81f3-09418ac94c34
http://forums.asp.net/t/1284389.aspx/1?How+to+make+LDAP+working+i+got+Unknown+error+0x80005000+
http://msdn.microsoft.com/en-us/library/bw8k1as4.aspx