gpt4 book ai didi

c# - 事件目录 : The server could not be contacted using DirectorySearcher

转载 作者:行者123 更新时间:2023-11-30 21:44:40 24 4
gpt4 key购买 nike

我一直收到错误无法联系服务器。当我尝试运行我的代码时:

我已经搜索了几个小时,仍然无法联系到服务器。

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所在的域改成了domain。

最佳答案

这里的关键语句似乎是“我将 AD 所在的域更改为域。”

  1. 确保应用服务器指向正确的 DNS 服务器。
  2. 确保客户端指向正确的 DNS 服务器。
  3. 此连接字符串看起来有误:PrincipalContext pricipalContext = new PrincipalContext(ContextType.Domain, "LDAP://domain.dk/DC=domain,DC=dk");

  4. #3 中的连接字符串可能像这样工作得更好:

    PrincipalContext pricipalContext = new PrincipalContext(ContextType.Domain, "DOMAIN", "DC=domain,DC=dk");

关于c# - 事件目录 : The server could not be contacted using DirectorySearcher,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40715521/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com