【问题标题】:Assigning multiple value property 'directReports' using System.DirectoryServices Active Directory APIs使用 System.DirectoryServices Active Directory API 分配多值属性“directReports”
【发布时间】:2015-04-26 19:07:33
【问题描述】:

我最初尝试将多个值作为 directReports 分配给 Active Directory 中的用户是使用 DirectoryEntry 对象并按如下方式分配:

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# 分配直接下属的多值属性?

【问题讨论】:

    标签: c# active-directory


    【解决方案1】:

    我相信directReports 是 Active Directory 中的计算字段。

    如果您有 10 名员工和同一个经理,那么该经理的 directReports 属性将列出所有这 10 名员工。

    但是您不能自己直接设置该属性 - 您必须设置员工的 manager 属性,然后 Active Directory 将自动设置经理的 directReports 属性

    【讨论】:

    • 我读到“此属性包含直接向用户报告的用户列表。作为报告列出的用户是那些将属性管理器属性设置为此用户的用户。列表中的每个项目是对代表用户的对象的链接引用。”在msdn.microsoft.com/en-us/library/cc221482.aspx 上,但无法猜到你在说什么。感谢您的提醒。
    • 我猜在将directReports属性添加到条目之前(在从属上添加manager属性之后)会有延迟。知道要多久吗?你的回答让我很开心,非常感谢!!!
    猜你喜欢
    • 2022-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多