2012-08-15 100 views
-1

我有這樣的LDAP連接字符串:connectionString="LDAP://username:[email protected]:389/DC=ABC,DC=local"LDAP連接字符串

Active Directory服務器是ABC.local與IP 10.10.10.246

我使用此代碼從Active Directory讀取性能:

MembershipSection membershipSection = (MembershipSection)WebConfigurationManager.GetSection("system.web/membership"); 
    string defaultProvider = membershipSection.DefaultProvider; 
ProviderSettings providerSettings = membershipSection.Providers[defaultProvider]; 
string connectionStringName = providerSettings.Parameters["connectionStringName"]; 
string connectionString = WebConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString; 
DirectoryEntry ent = new DirectoryEntry(connectionString); 
string name = ent.Properties["l"].Value.ToString(); 
string Language = ent.Properties["st"].Value.ToString(); 

但出現一個錯誤說"The server is not operational."。我正在做什麼與連接字符串或發生什麼事。你能幫我嗎?

+0

那是錯誤消息的應用消息或它的到來直接從異常?如果前者,實際的異常和堆棧跟蹤是什麼? – EJP 2013-08-17 23:52:04

回答

-1

下面是關於ServerFault LDAP connection string和這裏StackOverFlow

一個解釋你不應該在連接字符串中使用IP地址,這是一個壞習慣。 就你而言,我認爲它應該是這樣的:LDAP://ABC.local/DC=ABC,DC=local

這可以在每次需要搜索AD中的對象時使用:LDAP://OU=Users,DC=ABC,DC=local等等。

關於認證,有an explanation here,那給你:

DirectoryEntry dirEntry = new DirectoryEntry(connectionString, username, password);

我希望幫助。

+0

只有當LDAP服務器在本地主機上運行時,不帶主機名的LDAP URL纔可用。使用IP地址而不是主機名不會導致此問題。這裏沒有驗證錯誤的證據。 -1 – EJP 2013-08-17 23:50:02

+0

他從來沒有提到他的服務器沒有AD功能......我提出了一個解決方案。而使用IP地址並不是最好的解決方案。 – Gnial0id 2013-08-19 06:42:46

-1

連接字符串是不正確,你應該使用另外一個,並通過不同的方式初始化的DirectoryEntry條目:

string connectionString="LDAP://10.10.10.246/DC=ABC,DC=com"; // You can use also simple "LDAP://DC=ABC,DC=com" without IP 
DirectoryEntry ent = new DirectoryEntry(connectionString, userName, password); 
string name = ent.Properties["name"].Value.ToString(); // Note that property 'l' has friendly name 'City', it's unavailable for domain object! 
+0

如果LDAP服務器在同一主機上運行,​​則只能從URL中省略IP地址。這裏沒有證據證明認證問題。 -1。 – EJP 2013-08-17 23:50:27

+0

我很抱歉,但我從來沒有見過用戶登錄可以通過PATH參數,它的常見做法是將新的Directory Entry調用中的用戶名和密碼設置爲添加參數,但不在路徑中,在我看來,它是這個代碼中的問題。 MSDN鏈接:http://msdn.microsoft.com/en-US/library/ms180841(v=vs.80).aspx 當然,使用域名或服務器名稱而不是IP是在優先 – thezar 2013-08-21 09:53:57