我正在尝试创建一个用户并将其添加到 3 个组,创建工作正常,但将用户添加到组有时可以正常工作,有时会显示此错误:
there is no such object on the server
我将用户添加到组的代码:
try
{
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://" + group, ADUsername, ADPassword);
if (dirEntry != null)
{
dirEntry.Properties["member"].Add(userPrincipal.DistinguishedName);
dirEntry.CommitChanges();
dirEntry.Close();
}
}
catch (System.DirectoryServices.DirectoryServicesCOMException E)
{
//doSomething with E.Message.ToString();
}
最佳答案
我经历过这种情况,在我的情况下,这是因为新创建的对象没有复制到我们所有的 DC。我通过在创建用户后引入 3 秒延迟来解决此问题。然后我继续将用户添加到组中。
关于C# 将事件目录用户添加到组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52354106/