问题描述
我的最初尝试以directReports到Active Directory中的用户分配多个值均使用的DirectoryEntry对象,并分配如下:
My initial attempts to assign multiple values as directReports to a user in Active Directory were to use DirectoryEntry objects and assign as follows:
DirectoryEntry de; //get it from somewhere
de.Properties["directReports"].Value = object[] { "CN=user123,CN=Users,DC=DOMAIN,DC=xyz", "dn2", "dn3" };
de.CommitChanges(); //error: contraint violation occurred
这也为经理的属性没有工作。
It also didn't work for the "manager" attribute.
然后我开始使用UserPrincipal扩展方法(使用DirectoryEntries的背景下,对不对?)
I then started to use UserPrincipal extension methods (which use DirectoryEntries in the background, right?)
[DirectoryRdnPrefix("CN")]
[DirectoryObjectClass("Person")]
public class UserPrincipalEx : UserPrincipal
{
public UserPrincipalEx(PrincipalContext pc)
: base(pc)
{
}
public void SetManager(string value)
{
this.ExtensionSet("manager", value);
}
public void SetDirectReports(string[] values)
{
//foreach(var v in values)
this.ExtensionSet("directReports", values);
}
public static new UserPrincipalEx FindByIdentity(PrincipalContext context, string identityValue)
{
return (UserPrincipalEx)FindByIdentityWithType(context, typeof(UserPrincipalEx), identityValue);
}
public static new UserPrincipalEx FindByIdentity(PrincipalContext context, IdentityType identityType, string identityValue)
{
return (UserPrincipalEx)FindByIdentityWithType(context, typeof(UserPrincipalEx), identityType, identityValue);
}
}
通过发送专有名称字符串指定一名经理工作得很好,但它并不适用于直接报告工作。我仍然得到 InvalidOperationException异常:出现一个约束冲突
我想这样称呼它:
PrincipalContext pc = new PrincipalContext(ContextType.Domain, "mazen", user, pass);
UserPrincipalEx up = UserPrincipalEx.FindByIdentity(pc, IdentityType.SamAccountName, "moses");
var dns = new string[] { "CN=someone,CN=Users,DC=DOMAIN,DC=xyz", "CN=anotherone,CN=Users,DC=DOMAIN,DC=xyz" };
up.SetDirectReports(dns);
使用C#一个人怎么可以分配的直接下属多值属性?
How can one assign the direct reports multi-value property using C#?
推荐答案
我相信 directReports
是计算在Active Directory域。
I believe the directReports
is a calculated field in Active Directory.
如果您有10名员工使用相同的经理,然后是经理的 directReports
属性将列出所有的10名员工。
If you have 10 employees with the same manager, then that manager's directReports
property will list all those 10 employees.
不过,您不能直接设置自己的财产 - 你必须设置员工的管理
属性,然后经理的 directReports
属性将被由Active Directory自动设置
But you cannot directly set that property yourself - you have to set the employee's manager
property, and then the manager's directReports
property will be set automatically by Active Directory
这篇关于分配多值属性使用System.DirectoryServices中的Active Directory的API“directReports”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!