LDAP: Connect to default Domain Controller using current user credentials

Connect to the default DC and authenticate with the current user.

Date Entered: 10/23/2015    Last Updated: 10/23/2015

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 ldap1.Config("UseDefaultDC=true"); //Specify the Negotiate mechanism so the current users credentials can be used with NTLM/Negotiate ldap1.AuthMechanism = LdapAuthMechanisms.amNegotiate; ldap1.Bind(); //After binding search the root to find the default DN ldap1.DN = ""; ldap1.SearchScope = LdapSearchScopes.ssBaseObject; ldap1.Search("objectClass=*"); string defaultDN = ldap1.Attr("defaultNamingContext");

Additionally the component can be used to simply query for the default Domain Controller at any time: Console.WriteLine(ldap1.Config("DomainController"));


We appreciate your feedback.  If you have any questions, comments, or suggestions about this entry please contact our support team at kb@nsoftware.com.