Active directory LDAP连接字符串

Active directory LDAP连接字符串,active-directory,ldap,Active Directory,Ldap,我有这个LDAP连接字符串:connectionString=“LDAP://username:password@10.10.10.246:389/DC=ABC,DC=local“ Active directory服务器是IP10.10.10.246的ABC.local 我正在使用以下代码从active directory读取属性: MembershipSection membershipSection = (MembershipSection)WebConfigurationManager.G

我有这个LDAP连接字符串:
connectionString=“LDAP://username:password@10.10.10.246:389/DC=ABC,DC=local“

Active directory服务器是IP
10.10.10.246
的ABC.local

我正在使用以下代码从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();

但是出现了一个错误,提示“服务器无法运行。”。我是否正在使用连接字符串编写日志或正在发生的事情。您能帮帮我吗?

这里是关于in-ServerFault和in-Here的解释

您不应该在连接字符串中使用IP地址,这是一个坏习惯。 在您的情况下,我认为应该是这样的:
LDAP://ABC.local/DC=ABC,DC=local

每次需要搜索广告中的对象时都可以使用此选项:
LDAP://OU=Users、DC=ABC、DC=local
等等

关于身份验证,有以下几点:

DirectoryEntry dirEntry=新的DirectoryEntry(连接字符串、用户名、密码)


我希望这会有所帮助。

您的连接字符串不正确,您应该使用另一个连接字符串,并以不同的方式初始化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!

只有在本地主机上运行LDAP服务器时,不带主机名的LDAP URL才有效。使用IP地址而不是主机名不会导致此问题。这里没有验证错误的证据-1他从未提到他的服务器没有广告功能。。。我提出了一个解决办法。使用IP地址并不是最好的解决方案。如果LDAP服务器运行在同一主机上,则只能从URL中省略IP地址。这里没有证据表明存在身份验证问题-1.很抱歉,但我从未见过用户登录可以在PATH参数中传递,它的常见做法是在新目录条目调用中将用户名和密码设置为addition参数,但不在PATH中,在我看来,这就是代码中的问题。MSDN链接:当然,使用域名或服务器名而不是IP是首选。错误消息是应用程序消息还是直接来自异常?如果是前者,实际的异常和堆栈跟踪是什么?