2010-04-23 2 views
4

개체 클래스 사람uidObject을 사용하여 OpenLDAP에 새 사용자 레코드를 만들려고합니다. 문제는 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)

답변

6

그것은 당신이 항목을 먼저 LDAP 및 인출에 저장된 후 객체 클래스를 추가 할 수 있습니다 밝혀 다시. 그래서 간단한 변화만으로도 잘 작동합니다!

DirectoryEntry newUser = nRoot.Children.Add("CN=" + "test", "person"); 
newUser.Properties["cn"].Add("test"); 
newUser.Properties["sn"].Add("test"); 
newUser.CommitChanges(); 

newUser.RefreshCache(); 
newUser.Properties["objectClass"].Add("uidObject"); 
newUser.Properties["uid"].Add("testlogin"); 
newUser.CommitChanges(); 
관련 문제