2011-04-06 53 views
5

我有一個使用System.DirectoryServices.AccountManagement類的.NET 3.5 Web應用程序。當我搜索一些用戶時,我得到一個PrincipalOperationException:從服務器返回一個引用。如果我使用自己的LDAP代碼實現了舊式的學習方式,那麼我可以啓用追蹤引薦。我是否需要重寫我的代碼?有沒有辦法啓用引用追逐UserPrincipal.FindByIdentity()?

我的代碼如下所示:

using (var principalContext = new PrincipalContext(ContextType.Domain, null, adPath)) 
    { 

     // Find the principal object for which you wish to enumerate group 
     // membership. 
     using (var userPrincipal = UserPrincipal.FindByIdentity(principalContext, identity)) 
     { 
      if (userPrincipal != null) 
      { 
       Name = userPrincipal.DisplayName; 
       DistinguishedName = userPrincipal.DistinguishedName; 
       EmailAddress = userPrincipal.EmailAddress; 
       Sid = userPrincipal.Sid.Value; 
      } 
     } 
    } 

我adPath可以在2個值之一。其中一個值是最近加入的域,可以使用不同的工具訪問。我相信這是.NET庫如何進行LDAP調用的問題。

+0

也許您可以至少添加更多標籤[.net-3.5],[windows-server-2008]或[windows-server]。 – JPBlanc 2011-04-07 05:50:37

回答

1

這是部分答案,因爲評論太長。

根據this Microsoft documentation,你甚至知道,推薦是暗示,客戶可以追逐。但是關於RODC,他們添加了「例如,對於LDAP應用程序,如果在客戶端和RODC之間的LDAP連接上啓用了追逐引用,那麼應用程序永遠不會知道客戶端收到來自RODC的引用。會自動重定向到引用中指定的可寫域控制器。「」。

因此,我看看如何啓用LDAP追趕Microsoft網站中的連接和I found this這意味着ADSI使用。我對答案非常感興趣。

你嘗試查詢全局編錄如下:

/* Retreiving a principal context 
*/ 
PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, "YourGCServer:3268", "dc=dom,dc=fr", "User", "Password"); 

它應該包含所有林中的域的DATAS。 我希望它有幫助。

+0

這不是很有幫助。我知道推介是如何運作的,而且我需要弄清楚如何強制推介這個特定的API。 – 2011-04-07 21:06:31

+0

我編輯我的aswer。 – JPBlanc 2011-04-11 19:39:09

0

你有沒有嘗試過的形式的代碼(把域作爲第二個參數):

var principalContext = new PrincipalContext(ContextType.Domain, "office.local", "OU=Users, DC=office, DC=local")) 

另外,還要確保adPath是從最具體到最不具體。

相關問題