web analytics

"A local error has occurred." when accessing the LDAP server in C#

Options

codeling 1599 - 6654
@2015-12-30 18:38:34

When I try to access my LDAP server with the following C# code:

DirectoryEntry entry = new DirectoryEntry();
entry.Path = "LDAP Server and Path";
entry.Username = "userid";
entry.Password = "password";

DirectorySearcher ds = new DirectorySearcher(entry);
ds.Filter = string.Empty
ds.SearchScope = SearchScope.Subtree;

SearchResultCollection results = ds.FindAll();

I get DirectoryServicesCOMException thrown saying:

"A local error has occurred.".

After having done some investigation, I notice the above code did not specify the AuthenticationType value, it seems that my Windows Server 2008 security doesn't like the default value in the AuthenticationType.

Assigning None value to the AuthenticationType will get rid of the exception.

DirectoryEntry entry = new DirectoryEntry();
entry.Path = "LDAP Server and Path";
entry.Username = "userid";
entry.Password = "password";
entry.AuthenticationType = AuthenticationTypes.None;

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com