What's the connection string for LDAP?

2019-02-20 12:57发布

问题:

Here how I need to use it:

string tmpDirectory = String.Format("LDAP://ou={0},dc={1},dc={2}", 
                                    parentOrganizationUnit,
                                    domainName,
                                    domainExtension
);

When I try to run some code using this connection, I get an exception. (See this question for more information).

I've been told I need to provide the connection string with credentials - a username and a password.

What's the connection string like? I need the exact syntax. :) Thanks!

I'm using Windows Server 2003 and Active Directory.

回答1:

The credentials don't go into the connection string, but are separate parameters on another overload of the DirectoryEntry constructor:

var entry = new DirectoryEntry(tmpDirectory, "username", "password");