从服务器返回了推荐

时间:2013-05-22 08:18:58

标签: c# asp.net active-directory

我正在使用以下代码:

   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;
        }

并收到此错误: A referral was returned from the server.

来自:SearchResult result = search.FindOne();

我该如何解决这个问题?

0 个答案:

没有答案