2016-02-13 69 views
1

我想搜索在林中所有域和我這樣做以下列方式:C#:如何使用DirectoryContext,Domains和DirectoryEntry類啓用SSL連接到Active Directory?

foreach(Domain currDomain in Forest.GetCurrentForest().Domains) 
{ 
    try 
    { 
     DirectorySearcher searcher = new 
         DirectorySearcher(currDomain.GetDirectoryEntry()); 
     searcher.PageSize = 1000; 
     searcher.PropertiesToLoad.Add("cn"); 
     searcher.PropertiesToLoad.Add("distinguishedName"); 
     searcher.Filter = "(&(objectClass=group))"; 
     using (SearchResultCollection resList = searcher.FindAll()) 
     { 
     } 
    } 
} 

現在我想做的事與啓用SSL相同。要做到這一點,我試圖在的DirectoryEntry

AuthenticationType 

屬性設置爲

AuthenticationTypes.SecureSocketsLayer. 

但是,當我嘗試執行,「的操作錯誤發生」異常被拋出。

有人可以幫助我嗎?

回答

0

安全LDAP(LDAPS)偵聽與常規LDAP(389)不同的端口(636)。您需要告訴它在該端口上連接。試試這個:

DirectorySearcher searcher = new 
        DirectorySearcher(new DirectoryEntry("LDAP://" + currDomain.Name + ":636"); 
0

哇!我從的回答中得到了這個工作。最初,我修改爲從第1個答案的幫助下給予代碼:

DirectoryEntry de = new DirectoryEntry("LDAP://" + currDomain.Name + ":636") 
DirectorySearcher searcher = new DirectoySearcher(searcher); 

但我仍然得到「的操作時發生錯誤」。然後,我想通了,我有以下的代碼,以及:

de.AuthenticationType = AuthenticationTypes.SecureSocketLayer. 

當我刪除了上述行,它開始工作正常,我使用Wireshark證實了它。

相關問題