1

I'm using the following code:

   private string GetTitle(string userName)
        {
              string title = string.Empty;

            try
            {
                DirectoryEntry myLdapConnection = createDirectoryEntry();

                DirectorySearcher search = new DirectorySearcher(myLdapConnection);
                search.ReferralChasing = ReferralChasingOption.All;
                search.Filter = "(cn=" + userName + ")";
                search.PropertiesToLoad.Add("title");



                SearchResult result = search.FindOne();

                if (result != null)
                {
                    // create new object from search result  

                    DirectoryEntry entryToUpdate = result.GetDirectoryEntry();

                    title = entryToUpdate.Properties["title"][0].ToString();
                }

                else Console.WriteLine("User not found!");
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught:\n\n" + e.ToString());
            }

            return title;
        }

and get this error: A referral was returned from the server.

from line: SearchResult result = search.FindOne();

How can I solve this?

Elad Benda
  • 35,076
  • 87
  • 265
  • 471
  • see this http://stackoverflow.com/questions/6954170/a-referral-was-returned-from-the-server-exception-when-accessing-ad-from-c-sha – Zaki May 22 '13 at 08:20

0 Answers0