LDAP: Connect to default Domain Controller using current user credentials
The LDAP component can be used to connect to the default Domain Controller and authenticate using the current user credentials. This means that server and user information does not need to be set before calling Bind. After binding a simple search can be used to find the default DN to be used for further operations.
This approach can be used to provide a friction-free connection experience for the user. Please see the example code below for details.
//Tell the component to use the default Domain Controller as the server
//Specify the Negotiate mechanism so the current users credentials can be used with NTLM/Negotiate
ldap1.AuthMechanism = LdapAuthMechanisms.amNegotiate;
//After binding search the root to find the default DN
ldap1.DN = "";
ldap1.SearchScope = LdapSearchScopes.ssBaseObject;
string defaultDN = ldap1.Attr("defaultNamingContext");
Additionally the component can be used to simply query for the default Domain Controller at any time:
We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at firstname.lastname@example.org.