using System; using System.IO; using System.DirectoryServices; using System.Configuration; try { DirectoryEntry userEntry = new DirectoryEntry("LDAP://SERVERIP/OU=ORG,DC=UAT,DC=COM", user, password); DirectorySearcher search = new DirectorySearcher(userEntry); search.SearchScope = SearchScope.Subtree // Search user test02 search.Filter = "(&(objectClass=user)(objectCategory=Person)(sAMAccountName=test02))"; SearchResult result = search.FindOne(); // Failed at this line, throw exception if (result == null) Console.WriteLine("There is no results to display"); else Console.WriteLine("Found result "); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); Console.WriteLine("Trece: " + ex.StackTrace); }
Error: Configuration system failed to initialize<br /> Trece: at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)<br /> at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)<br /> at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)<br /> at System.Configuration.ConfigurationManager.GetSection(String sectionName)<br /> at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)<br /> at System.DirectoryServices.SearchResultCollection.ResultsEnumerator..ctor(SearchResultCollection results, String parentUserName, String parentPassword, AuthenticationTypes parentAuthenticationType)<br /> at System.DirectoryServices.SearchResultCollection.GetEnumerator()<br /> at System.DirectoryServices.DirectorySearcher.FindOne()<br />
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)