我正在尝试向Active Directory中的用户条目添加属性/属性。使用以下代码更新属性值没有任何问题。
string LDAPString = "LDAP://DC=oc,DC=edu";
DirectoryEntry ou = new DirectoryEntry(LDAPString, "fakeUsername", "password");
DirectorySearcher searcher = new DirectorySearcher(ou);
searcher.Filter = "sAMAccountName=" + username;
SearchResult result = searcher.FindOne();
DirectoryEntry user = new DirectoryEntry(result.Path, "fakeUsername", "password");
user.Properties[propertyName].Value = propertyValue;
user.CommitChanges();
user.Dispose();但是,当我尝试添加一个新项并调用CommitChanges()时,它会引发一个错误:
指定的目录服务属性或值不存在。
ExtendedErrorMessage说:
00000057: LdapErr: DSID-0C090B8A,注释:属性转换操作错误,数据0,v1db1
string propertyName = "test";
string propertyValue = "testValue";
user.Properties[propertyName].Add(propertyValue);
user.CommitChanges();我有一种感觉,我错过了一些简单的东西,但我似乎无法弄清楚。
发布于 2012-08-29 15:12:42
我不知道通常不会出现一个属性/属性,除非它填充了一个值。正如marc_s所暗示的,该属性已经存在于模式中,您只需用一个值填充它。
https://stackoverflow.com/questions/12163273
复制相似问题