2012-08-15 173 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