我的初步尝试将多个值directReports到Active Directory用户要使用的DirectoryEntry对象,并分配如下:分配多值属性“directReports”使用的System.DirectoryServices Active Directory中的API
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
它也不适用于“经理”属性。
然后我开始使用UserPrincipal扩展方法(使用DirectoryEntries的背景下,对吧?)
[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: A constraint violation occurred.
我想这样称呼它:
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#一个分配的直接报告多值属性?
我读“此属性包含用户的列表直接向用户报告,列为报告的用户是那些将属性管理器属性设置为该用户的用户,列表中的每个项目都是代表用户的对象的链接引用。在https://msdn.microsoft.com/en-us/library/cc221482.aspx上,但不能猜到你说什么。感谢您的提醒。 – Mzn
我猜测在将directReports属性添加到条目之前存在延迟(在管理员属性添加到下属之后)。任何想法多久?你用你的答案让我的一天,非常感谢! – Mzn