[英]How do I clear out a user object attribute in Active Directory?
Suppose you have connected to Active Directory using the simple syntax: 假设您使用简单语法连接到Active Directory:
string adPath = "LDAP://server.domain.com/CN=John,CN=Users,dc=domain,dc=com";
DirectoryEntry userEntry = Settings.GetADEntry(adPath);
Now, you find that you would like to see an attribute for that user. 现在,您发现您希望查看该用户的属性。 Let's try to display the mail attribute (which stands for email address):
让我们尝试显示邮件属性(代表电子邮件地址):
Console.WriteLine("User's mail attribute is " + userEntry.Properties["mail"]);
How can I delete the mail attribute value, since setting it to an empty string will not throw an error? 如何删除邮件属性值,因为将其设置为空字符串不会引发错误?
It turns out to be pretty simple, albeit not very commonly used... 事实证明这很简单,虽然不是很常用......
string adPath = "LDAP://server.domain.com/CN=John,CN=Users,dc=domain,dc=com";
DirectoryEntry userEntry = Settings.GetADEntry(adPath);
userentry.Properties["mail"].Clear();
userentry.CommitChanges();
Not sure that you can delete it since user objects usually follow a company schema but maybe something like the following will work: 不确定您是否可以删除它,因为用户对象通常遵循公司架构,但可能类似以下内容将起作用:
userEntry.Properties["mail"] = null;
or maybe: 或者可能:
userEntry.Invoke("Put", "mail", null);
then: 然后:
userEntry.CommitChanges();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.