使用C#需要当前组织中的所有用户详细信息(姓名,电子邮件,指定,部门)

阿克沙伊

我已经按照此链接C#LDAP查询来检索组织单位中的所有用户,并且从C#访问AD时出现“从服务器返回了引用”异常

我需要知道我在LDAP路径中做错了什么吗?

 // create your domain context and define what container to search in - here OU=Employees
        PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "MS", "OU=Employees,DC=CompanyName,DC=com");

        // define a "query-by-example" principal - here, we search for a UserPrincipal 
        // that is still active
        UserPrincipal qbeUser = new UserPrincipal(ctx);
        qbeUser.Enabled = true;

        // create your principal searcher passing in the QBE principal    
        PrincipalSearcher srch = new PrincipalSearcher(qbeUser);

        // find all matches
        foreach (var found in srch.FindAll())
        {
            // do whatever here - "found" is of type "Principal" - it could be user, group, computer.....          
        }

我需要使用C#当前组织中的所有用户详细信息(姓名,电子邮件,指定,部门),并将其显示在下拉列表中。请帮忙。

阿克沙伊
public DataTable FindPersons(string lname, string fname)
    { 

        DirectorySearcher searcher = new DirectorySearcher();
        searcher.Filter = string.Format("(&(objectCategory=person)(objectClass=user)(givenname={0}*)(sn={1}*))", fname, lname);

        SearchResultCollection allResults;
        allResults = searcher.FindAll();

        DataTable dt = new DataTable();
        dt.Columns.Add("DisplayName", typeof(string));
        dt.Columns.Add("GivenName", typeof(string));
        dt.Columns.Add("SurName", typeof(string));
        dt.Columns.Add("MSID", typeof(string));
        if (allResults.Count >= 0)
        { 
            for (int i = 0; i < allResults.Count; i++)
            {
                DirectoryEntry deMembershipUser = allResults[i].GetDirectoryEntry();
                deMembershipUser.RefreshCache(); 

                dt.Rows.Add(
                    (string)deMembershipUser.Properties["displayname"].Value, 
                    (string)deMembershipUser.Properties["givenName"].Value,
                    (string)deMembershipUser.Properties["sn"].Value, 
                    (string)deMembershipUser.Properties["cn"].Value
                    ); 
            } 
        } 
        return dt;
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Google登录中的导航抽屉上显示用户详细信息,例如姓名,电子邮件和图像?

从TwitterOAut获取用户详细信息(例如电子邮件,生日和姓名)

从Android手机的联系人列表中检索指定号码的组织详细信息和电子邮件详细信息?

我正在使用 nodemailer 并且需要向数组中的所有用户发送电子邮件?

我需要向数组中的所有用户发送电子邮件

在 Gmail-Addon 中无法访问当前的电子邮件详细信息

使用加入或别名获取具有相同报告电子邮件地址的用户的详细信息

根据数组中存在的电子邮件ID向用户发送晚餐详细信息

Crashlytics:如何查看崩溃详细信息中的用户名/电子邮件/ ID?

如何将用户输入的详细信息发送到iOS中的电子邮件?

所有用户执行的sudo命令的详细信息

如何获取所有用户详细信息

如何使用LDAP从Active Directory获取所有用户的详细信息

使用mailx登录有关用户的电子邮件whois详细信息-使用sed的whois输出格式不起作用

如何在 Flutter 中的电子邮件验证后将用户详细信息添加到 Firestore DB?

在iOS中从Twitter获取用户个人资料详细信息(尤其是电子邮件地址)

创建所有用户的电子邮件列表

电子邮件包含“ @MyDomain”的所有用户

验证 Firebase 中所有用户的电子邮件

是否可以获取用户回复的电子邮件的详细信息?

使用 Microsoft Graph SDK 获取具有特定电子邮件域的所有用户

ionic,firebase:如何从firebase身份验证中获取所有用户电子邮件

在Laravel中通过ID获取所有用户的电子邮件

如何绕过Paypal结帐并使用servlet通过javamail中的电子邮件发送simplecart详细信息?

列表退订(RFC 2369)的电子邮件详细信息

Mysql查询以查找对评论发表评论的所有用户的用户详细信息?

在 WooCommerce 电子邮件通知中重新排列客户详细信息

在WooCommerce电子邮件中查找/编辑订单详细信息元文本

Woocommerce电子邮件通知中的样式订单详细信息表