4
我想創建一個新的用戶記錄到OpenLDAP與對象類人和uidObject。這個問題似乎是與System.DirectoryServices.DirectoryEntry我發現只有一種方法來添加一個對象類,但沒有添加多個對象類的方式。C#如何添加一個條目到LDAP與多個對象類
此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);
}
...導致錯誤:
-2147016684 The requested operation did not satisfy one or more constraints associated with the class of the object. (Exception from HRESULT: 0x80072014)