简体   繁体   English

Active Directory添加用户属性

[英]Active Directory Adding User Properties

I am trying to add a property/attribute to a user entry in Active Directory. 我正在尝试向Active Directory中的用户条目添加属性/属性。 I don't have any trouble updating property values using the following code. 使用以下代码更新属性值没有任何麻烦。

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();

However when I try to add a new item and call CommitChanges() it throws an error: 但是,当我尝试添加新项目并调用CommitChanges() ,会引发错误:

The specified directory service attribute or value does not exist. 指定的目录服务属性或值不存在。

The ExtendedErrorMessage says the following: ExtendedErrorMessage表示以下内容:

00000057: LdapErr: DSID-0C090B8A, comment: Error in attribute conversion operation, data 0, v1db1 00000057:LdapErr:DSID-0C090B8A,注释:属性转换操作出错,数据0,v1db1

string propertyName = "test";
string propertyValue = "testValue";
user.Properties[propertyName].Add(propertyValue);
user.CommitChanges();

I have a feeling I am missing something simple but I can't seem to figure it out. 我觉得我缺少一些简单的东西,但似乎无法弄清楚。

I did not understand that typically a property/attribute does not appear unless it is populated with a value. 我不了解,通常除非显示一个属性/属性,否则不会显示该属性/属性。 As marc_s alluded to the property is already there in the schema you just have to populate it with a value. 由于在属性中已经包含了指向该属性的marc_s,因此您只需为它填充一个值即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM