1. <small id='zY7kj'></small><noframes id='zY7kj'>

      <bdo id='zY7kj'></bdo><ul id='zY7kj'></ul>
    <tfoot id='zY7kj'></tfoot>

  2. <i id='zY7kj'><tr id='zY7kj'><dt id='zY7kj'><q id='zY7kj'><span id='zY7kj'><b id='zY7kj'><form id='zY7kj'><ins id='zY7kj'></ins><ul id='zY7kj'></ul><sub id='zY7kj'></sub></form><legend id='zY7kj'></legend><bdo id='zY7kj'><pre id='zY7kj'><center id='zY7kj'></center></pre></bdo></b><th id='zY7kj'></th></span></q></dt></tr></i><div id='zY7kj'><tfoot id='zY7kj'></tfoot><dl id='zY7kj'><fieldset id='zY7kj'></fieldset></dl></div>

    <legend id='zY7kj'><style id='zY7kj'><dir id='zY7kj'><q id='zY7kj'></q></dir></style></legend>

      从 AD 获取用户详细信息很慢

      时间:2023-10-24

      • <legend id='sJDBB'><style id='sJDBB'><dir id='sJDBB'><q id='sJDBB'></q></dir></style></legend>

            <tfoot id='sJDBB'></tfoot>

          1. <small id='sJDBB'></small><noframes id='sJDBB'>

                <tbody id='sJDBB'></tbody>

              <i id='sJDBB'><tr id='sJDBB'><dt id='sJDBB'><q id='sJDBB'><span id='sJDBB'><b id='sJDBB'><form id='sJDBB'><ins id='sJDBB'></ins><ul id='sJDBB'></ul><sub id='sJDBB'></sub></form><legend id='sJDBB'></legend><bdo id='sJDBB'><pre id='sJDBB'><center id='sJDBB'></center></pre></bdo></b><th id='sJDBB'></th></span></q></dt></tr></i><div id='sJDBB'><tfoot id='sJDBB'></tfoot><dl id='sJDBB'><fieldset id='sJDBB'></fieldset></dl></div>
                <bdo id='sJDBB'></bdo><ul id='sJDBB'></ul>
                本文介绍了从 AD 获取用户详细信息很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用以下代码从特定部门获取有关员工的大量信息,并从 AD 返回列表...

                Im using the following code to get a bunch of information about employees from specific departments and returning a list from AD...

                虽然它有效,但似乎很慢,是否有更有效的方法从 AD 获取各种用户详细信息?

                Whilst it works, it appears to be quite slow, is a there more efficient way of getting various user details from AD?

                public static List<Employee> GetEmployeeListForDepartment(string departpment)
                        {
                            using (HostingEnvironment.Impersonate())
                            {
                
                                PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domain);
                                GroupPrincipal gp = GroupPrincipal.FindByIdentity(ctx, departpment);
                                PrincipalSearchResult<Principal> members = gp.GetMembers();
                                List<Employee> employees = new List<Employee>();
                                foreach (var member in members)
                                {
                                    var emp = CreateEmployee(member);
                                    employees.Add(emp);
                                }
                                return employees.OrderBy(x => x.FirstName).ToList();
                            }
                        }
                
                        private static Employee CreateEmployee(Principal member)
                        {
                            if (member != null)
                            {
                                DirectoryEntry de = (member.GetUnderlyingObject() as DirectoryEntry);
                                if (de != null)
                                {
                
                                    string mobile = de.Properties.Contains("mobile") ? de.Properties["mobile"][0].ToString() : "";
                                    string title = de.Properties.Contains("description") ? de.Properties["description"][0].ToString() : "";
                
                //ETC ETC...
                                    return new Employee { etc.. };
                
                                }
                
                            }
                            return new Employee();
                        }
                

                推荐答案

                您的问题是您正在使用 System.DirectoryServices.AccountManagement...虽然我讨厌这样说,但可悲的是事实.AccountManagement 在后台工作的方式是它运行一个单独的 LDAP 查询来单独检索每个项目.因此,当您遍历成员时,它会通过 LDAP 为每个成员进行单独的回调.您想要做的是使用 System.DirectoryServices.DirectorySearcher 运行 LDAP 查询.

                Your problem is that you are using System.DirectoryServices.AccountManagement... While I hate saying it, it's sadly the truth. The way AccountManagement works under the hood is that it runs a seperate LDAP query to retrieve each item seperately. So when you iterate through members it's making a seperate call back through LDAP for each member. What you want to do instead is run an LDAP query using System.DirectoryServices.DirectorySearcher.

                我的假设是,部门是一个组,这取决于你如何使用它.这是我将如何做到的.(我的代码在 VB.Net 中......对不起).确保为您的组获取完全限定的 DN,或者提前查找并将其插入查询中.

                My assumption is that department is a group, based on how you are using it. Here is how I would do it. (my code is in VB.Net... sorry). Make sure to get the fully qualified DN for your group, or look it up in advance and plug it into the query.

                Dim results = LDAPQuery("(memberOf=CN=Fully,OU=Qualified,DC=Group,DC=Distinguished,DC=Name)", New String() {"mobile", "description"})
                
                Dim emps = (from c as System.DirectoryServices.SearchResult in results _
                             Select New Employee() {.Name = c.Properties("description"), .Mobile = c.Properties("mobile")}).ToList()
                
                Public Function LDAPQuery(ByVal query As String, ByVal attributes As String()) As SearchResultCollection
                    'create directory searcher from CurrentADContext (no special security available)
                    Dim ds As New DirectorySearcher(System.DirectoryServices.ActiveDirectory.Domain.GetCurrentDomain().GetDirectoryEntry())
                    ds.PageSize = 1000
                
                    'set filter string
                    ds.Filter = query
                
                    'specify properties to retrieve
                    ds.PropertiesToLoad.AddRange(attributes)
                
                    'get results
                    Dim results As SearchResultCollection = ds.FindAll()
                
                    Return results
                End Function
                

                这篇关于从 AD 获取用户详细信息很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:尝试使用 LDAP 连接连接 AD 时出错 下一篇:无法使用内容同步操作 (syncrepl) 从 OpenLDAP 服务器获取已删除的项目

                相关文章

                <i id='H04Yr'><tr id='H04Yr'><dt id='H04Yr'><q id='H04Yr'><span id='H04Yr'><b id='H04Yr'><form id='H04Yr'><ins id='H04Yr'></ins><ul id='H04Yr'></ul><sub id='H04Yr'></sub></form><legend id='H04Yr'></legend><bdo id='H04Yr'><pre id='H04Yr'><center id='H04Yr'></center></pre></bdo></b><th id='H04Yr'></th></span></q></dt></tr></i><div id='H04Yr'><tfoot id='H04Yr'></tfoot><dl id='H04Yr'><fieldset id='H04Yr'></fieldset></dl></div>

                1. <legend id='H04Yr'><style id='H04Yr'><dir id='H04Yr'><q id='H04Yr'></q></dir></style></legend>
                    <tfoot id='H04Yr'></tfoot>

                    <small id='H04Yr'></small><noframes id='H04Yr'>

                    • <bdo id='H04Yr'></bdo><ul id='H04Yr'></ul>