从生产服务器上的Web服务访问Active Directory时出现错误
问题描述:
我收到以下错误消息以连接到Active Directory以通过Web服务获取用户信息。从生产服务器上的Web服务访问Active Directory时出现错误
指定的域不存在或无法联系。
但是,如果我在本地运行web服务,那没关系,我可以从web服务获取用户信息。
如果我以正常的方式(不是web服务)运行以下代码,它工作正常。如果我将其更改为Web服务,则只会出现此问题。有什么建议?谢谢。
[WebMethod]
public string[] GetADUserInfo(string SAMAccount)
{
DirectoryEntry entry = new DirectoryEntry("LDAP://xxxx", "username", "pwd");
try
{
string Filter = String.Format("(&(objectClass=user)(sAMAccountName={0}))", SAMAccount);
string[] properties = new string[] { "employeeid", "cn" };
DirectorySearcher Dsearch = new DirectorySearcher(entry, Filter, properties);
SearchResult result = Dsearch.FindOne();
xxxxxxx
xxxxxxx
}
catch (Exception ex)
{
Debug.Write("Err in GetADUserInfo : " + ex.Message);
}
return {"a","b"};
}
答
我刚刚发现答案。 以前,我的LDAP字符串是LDAP:// DC = AA,DC = BB,DC = CC取而代之的是
,我改变了它使用的域名,并变成像下面这样:
LDAP ://mydomain.com/DC=aa,DC=bb,DC=cc
我不确定这是否正确。但它适用于我。建议和建议,欢迎。