need help with the basics

Apr 22, 2014 at 7:26 PM
I have this in c#:
            string domain = "LDAP://ldap_server_prod:389/OU=Pays,ou=Organisations,o=algeco,c=com";
            string serviceUser = "uid=xxxxx,ou=services,o=algeco,c=com";
            string servicePassword = "xxxx";

            DirectoryEntry directoryEntry = new DirectoryEntry(domain, serviceUser, servicePassword,AuthenticationTypes.ServerBind);
            
            DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry)
            {
                Filter = "(&(objectClass=*))"
            };

            SearchResultCollection searchResultCollection = directorySearcher.FindAll();
I can't get it to work in Linq to LDAP

This is what i have so far:
            LdapDirectoryIdentifier ldapDirectoryIdentifier = new LdapDirectoryIdentifier("ldap_server_prod:389");
            NetworkCredential myCredentials = new NetworkCredential("", "xxxx", "xxxx");

            using (LdapConnection connection = new LdapConnection(ldapDirectoryIdentifier, myCredentials, AuthType.Basic))
            {
                using (var context = new DirectoryContext(connection))
                {
                    IQueryable<IDirectoryAttributes> countries = context.Query("ou=services,OU=Pays,ou=Organisations,o=algeco,c=com", objectClass: "*");
                }
            }
Coordinator
Apr 24, 2014 at 1:39 PM
Edited Apr 24, 2014 at 1:41 PM
Can you go into detail about what's not working?

The first thing I notice is if you are using basic authentication, you have to use the user's distinguished name like your S.DS example. You'll also want to set your protocol version to 3 (I assume your server is version 3).
            LdapDirectoryIdentifier ldapDirectoryIdentifier = new LdapDirectoryIdentifier("ldap_server_prod:389");
            NetworkCredential myCredentials = new NetworkCredential("uid=xxxxx,ou=services,o=algeco,c=com", "xxxx");

            using (LdapConnection connection = new LdapConnection(ldapDirectoryIdentifier, myCredentials, AuthType.Basic))
            {
                connection.SessionOptions.ProtocolVersion = 3;
                using (var context = new DirectoryContext(connection))
                {
                    IQueryable<IDirectoryAttributes> countries = context.Query("ou=services,OU=Pays,ou=Organisations,o=algeco,c=com", objectClass: "*");
                }
            }
Apr 24, 2014 at 5:08 PM
That was it!

Thanks!