1

我一直收到錯誤服務器無法聯繫。當我試圖運行我的代碼:Active Directory:無法使用DirectorySearcher聯繫服務器

我已經搜索了幾個小時,我仍然無法聯繫服務器。

DirectorySearcher directorySearcher = new DirectorySearcher(); 
string path = directorySearcher.SearchRoot.Path; 
DirectoryEntry directoryEntry = new DirectoryEntry(path); 

PrincipalContext pricipalContext = new PrincipalContext(ContextType.Domain, "LDAP://domain.dk/DC=domain,DC=dk"); 
//GroupPrincipal group = GroupPrincipal.FindByIdentity(pricipalContext, "(CN=" + department + ")"); 
GroupPrincipal group = GroupPrincipal.FindByIdentity(pricipalContext, "(CN=" + department + ")"); 


if (group != null) 
{ 
    foreach (Principal principal in group.Members) 
    { 
     UserPrincipal tu = principal as UserPrincipal; 

     DirectoryEntry de = tu.GetUnderlyingObject() as DirectoryEntry; 
     var store = de.InvokeGet("physicalDeliveryOfficeName").ToString(); 
     var storeNumber = de.InvokeGet("description").ToString(); 

     employees.Add(new AdEmployees() { name = principal.Name, phone = tu.VoiceTelephoneNumber, email = tu.EmailAddress, store = store.ToString(), storeNumber = storeNumber.ToString(), link = GenerateLink(principal.Name) }); 
    } 
} 

注:我改變了我的域名,其中AD所在域。

回答

1

這裏的關鍵語句似乎是「我將AD所在的域名更改爲域名。」

  1. 確保應用程序服務器指向正確的DNS服務器。
  2. 確保客戶端指向正確的DNS服務器。
  3. 此連接字符串看起來錯了:在#3 PrincipalContext pricipalContext = new PrincipalContext(ContextType.Domain, "LDAP://domain.dk/DC=domain,DC=dk");

  4. 連接字符串可能像這樣工作更好:

    PrincipalContext pricipalContext =新PrincipalContext(ContextType.Domain, 「域」,「DC =域, DC = DK「);

相關問題