We help IT Professionals succeed at work.
Get Started

LDAP:  "there is no such object on the server"

Tom Knowlton
Tom Knowlton asked
on
5,314 Views
Last Modified: 2012-05-12
Trying to connect to an LDAP server, and I get this message back:

"there is no such object on the server"


Here is my current attempt via C# code:

        public XmlDocument GetLDAPInfo(string filter)
        {
            XmlDocument xd = new XmlDocument();
            string domain = string.Empty;
            string userName = string.Empty;
            string passWord = string.Empty;
            AuthenticationTypes at = AuthenticationTypes.SecureSocketsLayer;
            StringBuilder sb = new StringBuilder();

            //****Connecting to LDAP active directory
          
            domain = @"LDAP://ldap.uits.uconn.edu";

                     

            userName = "uid=coop-faculty_adoptions,ou=accounts,dc=uconn,dc=edu";
            passWord = "xxxxxxxxxxxxxxxxxxxx";
                        
            //Create the object necessary to read the info from the LDAP directory
            DirectoryEntry entry = new DirectoryEntry(domain, userName, passWord, at);

            Response.Write(entry.Properties.Count.ToString());


            DirectorySearcher mySearcher = new DirectorySearcher(entry);
            SearchResultCollection results;
            mySearcher.Filter = filter;

            try
            {
                results = mySearcher.FindAll();  //ERROR ... ENTERS CATCH BLOCK AFTER THIS LINE EXECUTES

                if (results.Count > 0)
                {
                    Response.Write(results.Count.ToString());


                    sb.Append("<Users>");
                    foreach (SearchResult resEnt in results)
                    {
                        sb.Append("<User>");
                        ResultPropertyCollection propcoll = resEnt.Properties;
                        foreach (string key in propcoll.PropertyNames)
                        {
                            foreach (object values in propcoll[key])
                            {
                                switch (key)
                                {
                                    case "sn":
                                        sb.Append("<surname>" + values.ToString() + "</surname>");
                                        break;
                                    case "cn":
                                        sb.Append("<cn>" + values.ToString() + "</cn>");
                                        break;
                                    case "name":
                                        sb.Append("<name>" + values.ToString() + "</name>");
                                        break;
                                    case "givenname":
                                        sb.Append("<givenname>" + values.ToString() + "</givenname>");
                                        break;
                                    case "distinguishedname":
                                        sb.Append("<distinguishedname>" + values.ToString() + "</distinguishedname>");
                                        break;
                                    case "member":
                                        sb.Append("<member>" + values.ToString() + "</member>");
                                        break;
                                    case "initials":
                                        sb.Append("<initials>" + values.ToString() + "</initials>");
                                        break;
                                    case "postalcode":
                                        sb.Append("<postalcode>" + values.ToString() + "</postalcode>");
                                        break;
                                    case "l":
                                        sb.Append("<location>" + values.ToString() + "</location>");
                                        break;
                                    case "c":
                                        sb.Append("<c>" + values.ToString() + "</c>");
                                        break;
                                    case "mobile":
                                        sb.Append("<mobile>" + values.ToString() + "</mobile>");
                                        break;
                                    case "homephone":
                                        sb.Append("<homephone>" + values.ToString() + "</homephone>");
                                        break;
                                    case "title":
                                        sb.Append("<title>" + values.ToString() + "</title>");
                                        break;
                                    case "co":
                                        sb.Append("<co>" + values.ToString() + "</co>");
                                        break;
                                    case "st":
                                        sb.Append("<state>" + values.ToString() + "</state>");
                                        break;
                                    case "mail":
                                        sb.Append("<mail>" + values.ToString() + "</mail>");
                                        break;
                                    case "password":
                                        sb.Append("<password>" + values.ToString() + "</password>");
                                        break;
                                    case "samaccountname":
                                        sb.Append("<samaccountname>" + values.ToString() + "</samaccountname>");
                                        break;
                                    case "memberof":
                                        sb.Append("<memberof>" + values.ToString() + "</memberof>");
                                        break;
                                    case "uid":
                                        sb.Append("<userid>" + values.ToString() + "</userid>");
                                        break;
                                    case "description":
                                        sb.Append("<description>" + values.ToString() + "</description>");
                                        break;
                                }
                            }
                        }
                        sb.Append("</User>");
                    }
                    sb.Append("</Users>");
                    xd.LoadXml(sb.ToString());
                    return xd;
                }
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
            }
            sb.Append("<Users><User>None</User></Users>");
            xd.LoadXml(sb.ToString());
            return xd;
        }

Open in new window




the filter being passed into the method is:

uid=abc123

(replacing abc123 with an actual netid does work in a windows client I downloaded, but not in the code above)

I should also note that I WAS able to connect via a windows LDAP client found on the web here:

http://ldapadmin.sourceforge.net/


So the LDAP server is able to give me the information...   there is a problem with my C# code or the way I am requesting the info.


Comment
Watch Question
Web Developer
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE