【问题标题】:using GroupPrincipal can you get additional info from UserPrincipal使用 GroupPrincipal 你可以从 UserPrincipal 获得更多信息吗
【发布时间】:2012-11-28 14:42:41
【问题描述】:

我正在使用 GroupPrincipal 查找属于 AD 组成员的用户。

GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, "Advisors");

我需要从此查找中获取 EmployeeID 字段,但我相信这只能使用 UserPrincipal。

var members = group.Members.Select(x => new DomainContext() { EmployeeID = x.EmployeeId, FullName = x.DisplayName }).ToList();

有人知道解决办法吗?

【问题讨论】:

    标签: asp.net-mvc active-directory


    【解决方案1】:

    除非您使用底层的 DirectoryEntry/DirectorySearcher 类,否则您必须使用 UserPrincipal。

    您应该使用 .GetMembers() 而不是 .Members 然后您可以执行以下操作:

    var userMembers = group.GetMembers().OfType<UserPrincipal>();
    foreach( var member in userMembers) {
        string empid = member.EmployeeId; //do something with the EmployeeId
    }
    

    【讨论】:

    • 非常感谢@DigitalD!完美运行。
    猜你喜欢
    • 1970-01-01
    • 2012-06-17
    • 2010-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-24
    • 1970-01-01
    相关资源
    最近更新 更多