我正在尝试使用对象类person和uidObject在OpenLDAP中创建一个新的用户记录.问题似乎是使用System.DirectoryServices.DirectoryEntry我发现只有一种方法可以添加一个具有一个对象类的新条目,但不能添加多个对象类.
这个C#代码
DirectoryEntry nRoot = new DirectoryEntry(path);
nRoot.AuthenticationType = AuthenticationTypes.None;
nRoot.Username = username;
nRoot.Password = pwd;
try
{
DirectoryEntry newUser = nRoot.Children.Add("CN=" + "test", "person");
newUser.Properties["cn"].Add("test");
newUser.Properties["sn"].Add("test");
newUser.Properties["objectClass"].Add("uidObject"); // this doesnt't make a difference
newUser.Properties["uid"].Add("testlogin"); // this causes trouble
newUser.CommitChanges();
}
catch (COMException ex)
{
Console.WriteLine(ex.ErrorCode + "\t" + ex.Message);
}
Run Code Online (Sandbox Code Playgroud)
...导致错误:
-2147016684请求的操作不满足与对象类关联的一个或多个约束.(HRESULT异常:0x80072014)