简体   繁体   English

使用PrincipalContext搜索Active Directory组时,不会返回某些UserPrincipal属性

[英]When Searching Active Directory Groups Using PrincipalContext Certain UserPrincipal Properties are not Returned

I am writing a C# application to display users within a user supplied security group. 我正在编写一个C#应用程序,以显示用户提供的安全组中的用户。 It seems like all my test cases work except when I search against "Domain Users". 除了我搜索“域用户”时,似乎所有测试用例都可以正常工作。 When I do neither Surname or GivenName will return values. 当我不做时,Surname或GivenName都不会返回值。 All other groups return those values. 所有其他组均返回这些值。 I'm stumped. 我很沮丧

Test 1: Domain Admins 测试1:域管理员

Results: All Surname and GivenName displayed in GridView 结果:GridView中显示所有姓和名

Test 2: Domain Users 测试2:域用户

Results: No Surname or GivenName's are displayed 结果:没有显示姓氏或GivenName

Note: If I change the properties to any other AD User Property, eg, Name, SAM, etc., those all display without issue. 注意:如果我将属性更改为任何其他AD用户属性,例如Name,SAM等,则所有这些都将显示而不会出现问题。

namespace adsearch
{
    public partial class frmViewGroupMembers : Form
    {
        private string group;
        private DataTable GroupMembers = new DataTable();

        public frmViewGroupMembers()
        {
            InitializeComponent();
        }

        public void ShowGroupMembers(string groupName) {
            GroupMembers.Columns.Add("Last Name");
            GroupMembers.Columns.Add("First Name");


            using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "mydomain.local")) {
                using (GroupPrincipal group = GroupPrincipal.FindByIdentity(context, groupName))
                {
                    foreach (UserPrincipal user in group.GetMembers(true).OfType<UserPrincipal>())
                    {
                        GroupMembers.Rows.Add(user.Surname, user.GivenName);
                    }                  
                }
            }

            dgvGroupMembers.DataSource = GroupMembers;
            dgvGroupMembers.Sort(dgvGroupMembers.Columns[0], ListSortDirection.Ascending);
            this.Show();
        }      
    }
}

Have you checked in Active Directory to confirm that the User has the required fields filled in? 您是否已在Active Directory中签入以确认用户已填写必填字段? Often the assumption is made that filling in the "Display Name" is enough, but both the "First Name" (GivenName) and "Last Name" (SurName) need to be filled in for GivenName and SurName to be populated. 通常假设填写“显示名称”就足够了,但是“第一名称”(GivenName)和“姓氏”(SurName)都需要填写,才能填充GivenName和SurName。

在此处输入图片说明

' '

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM