How to test LDAP connection?

Mar 28, 2012 at 8:04 AM

hi, I want to konw when i configure the LDAP hostname and port, how to test whether it is correct? thanks

Mar 29, 2012 at 8:06 PM

If you enumerate the DirectoryContext ListServerAttributes method results that should serve as a test of the connection.  The values there are the same that you see when you make a connection with the server using LDP.EXE.

Mar 30, 2012 at 1:17 AM

thanks,but I want to use linq to ldap to write a small program that allows users to change the connection setting such as host parameter,Credentials. how can I know the user's settings are correct.

 

Coordinator
Mar 30, 2012 at 4:19 AM
Edited Mar 30, 2012 at 4:52 AM

If you issue a Bind request on the LdapConneciton it will tell you if the connection information is valid.  You can find more about it here.

 

//Using LdapConnection directly
LdapDirectoryIdentifier identifier = new LdapDirectoryIdentifier("server", 389);
LdapConnection connection = new LdapConnection(identifier);
connection.Bind();

//Using LdapConnectionFactory
var factory = new LdapConnectionFactory("server")
    .UsePort(389);
factory.GetConnection().Bind();

//Using via LdapConfiguration
var configuration = new LdapConfiguration();
configuration.ConfigureFactory("server")
    .UsePort(389);
configuration.ConnectionFactory.GetConnection().Bind();
Mar 31, 2012 at 1:31 AM

thanks.