【发布时间】:2012-08-28 16:06:41
【问题描述】:
我正在尝试将属性/属性添加到 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();
我感觉我错过了一些简单的东西,但我似乎无法弄清楚。
【问题讨论】:
-
是否在 Active Directory 中定义了该新属性?您是否扩展了 AD 架构?您不能只在 AD 中设置任意新属性......
标签: c# active-directory directoryentry