Active Directory:无法使用DirectorySearcher联系服务器
问题描述:
我一直收到错误服务器无法联系。当我试图运行我的代码:Active Directory:无法使用DirectorySearcher联系服务器
我已经搜索了几个小时,我仍然无法联系服务器。
DirectorySearcher directorySearcher = new DirectorySearcher();
string path = directorySearcher.SearchRoot.Path;
DirectoryEntry directoryEntry = new DirectoryEntry(path);
PrincipalContext pricipalContext = new PrincipalContext(ContextType.Domain, "LDAP://domain.dk/DC=domain,DC=dk");
//GroupPrincipal group = GroupPrincipal.FindByIdentity(pricipalContext, "(CN=" + department + ")");
GroupPrincipal group = GroupPrincipal.FindByIdentity(pricipalContext, "(CN=" + department + ")");
if (group != null)
{
foreach (Principal principal in group.Members)
{
UserPrincipal tu = principal as UserPrincipal;
DirectoryEntry de = tu.GetUnderlyingObject() as DirectoryEntry;
var store = de.InvokeGet("physicalDeliveryOfficeName").ToString();
var storeNumber = de.InvokeGet("description").ToString();
employees.Add(new AdEmployees() { name = principal.Name, phone = tu.VoiceTelephoneNumber, email = tu.EmailAddress, store = store.ToString(), storeNumber = storeNumber.ToString(), link = GenerateLink(principal.Name) });
}
}
注:我改变了我的域名,其中AD所在域。
答
这里的关键语句似乎是“我将AD所在的域名更改为域名。”
- 确保应用程序服务器指向正确的DNS服务器。
- 确保客户端指向正确的DNS服务器。
此连接字符串看起来错了:在#3
PrincipalContext pricipalContext = new PrincipalContext(ContextType.Domain, "LDAP://domain.dk/DC=domain,DC=dk");
-
连接字符串可能像这样工作更好:
PrincipalContext pricipalContext =新PrincipalContext(ContextType.Domain, “域”,“DC =域, DC = DK“);