<tfoot id='eqbKP'></tfoot>

  • <small id='eqbKP'></small><noframes id='eqbKP'>

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

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

      2. 如何使用 C# 更好地查询 Active Directory 中的多个域?

        How can I better query multiple domains in Active Directory using C#?(如何使用 C# 更好地查询 Active Directory 中的多个域?)
        <tfoot id='TgTG3'></tfoot>
        <legend id='TgTG3'><style id='TgTG3'><dir id='TgTG3'><q id='TgTG3'></q></dir></style></legend>
            <tbody id='TgTG3'></tbody>
            <bdo id='TgTG3'></bdo><ul id='TgTG3'></ul>

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

                1. <i id='TgTG3'><tr id='TgTG3'><dt id='TgTG3'><q id='TgTG3'><span id='TgTG3'><b id='TgTG3'><form id='TgTG3'><ins id='TgTG3'></ins><ul id='TgTG3'></ul><sub id='TgTG3'></sub></form><legend id='TgTG3'></legend><bdo id='TgTG3'><pre id='TgTG3'><center id='TgTG3'></center></pre></bdo></b><th id='TgTG3'></th></span></q></dt></tr></i><div id='TgTG3'><tfoot id='TgTG3'></tfoot><dl id='TgTG3'><fieldset id='TgTG3'></fieldset></dl></div>
                  本文介绍了如何使用 C# 更好地查询 Active Directory 中的多个域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将 LDAP/AD 搜索从仅在当前登录的域中搜索扩展到搜索 AD 中的所有域.该方法接收带有查询的字符串,并返回并返回一个 LDAPInformation 对象.

                  I am attempting to expand a LDAP / AD search from only searching in the currently logged in domain to searching all domains in the AD. The method takes in the string with the query and returns and return an LDAPInformation object.

                  虽然我在问,有没有比这种方式更好的方法来搜索名称?由于在按姓氏查找人时需要使用通配符,因此用户不友好(例如:Doe*).

                  While I am asking, is there any better way to search for the name than in this way? It is user unfriendly due to needing to use wildcards if looking for a person by last name (example: Doe*).

                      public static LDAPInformation[] GetGlobalAddressListVIAName(string nameQuery)
                      {
                          var currentForest = Forest.GetCurrentForest();
                          var globalCatalog = currentForest.FindGlobalCatalog();
                  
                          using (var searcher = globalCatalog.GetDirectorySearcher())
                          {
                              using (var entry = new DirectoryEntry(searcher.SearchRoot.Path))
                              {
                                  searcher.Filter = "(&(mailnickname=*)(objectClass=user)(displayName=" + nameQuery + "))";
                                  searcher.PropertyNamesOnly = true;
                                  searcher.SearchScope = SearchScope.Subtree;
                                  searcher.Sort.Direction = SortDirection.Ascending;
                                  searcher.Sort.PropertyName = "displayName";
                                  return searcher.FindAll().Cast<SearchResult>().Select(result => new LDAPInformation(result.GetDirectoryEntry())).ToArray();
                              }
                          }
                      }
                  

                  这是对象:

                      class LDAPInformation
                  {
                      internal LDAPInformation(DirectoryEntry entry)
                      {
                          //Section: HASH
                          this.sAMAccountName = (string)entry.Properties["sAMAccountName"].Value;
                  
                          //Section: Email
                          this.Mail = (string)entry.Properties["mail"].Value;
                  
                          //Section: Organziation
                          this.Description = (string)entry.Properties["description"].Value;
                          this.Company = (string)entry.Properties["company"].Value;
                          this.Title = (string)entry.Properties["title"].Value;
                          this.Department = (string)entry.Properties["department"].Value;
                  
                          //Section: Name
                          this.DisplayName = (string)entry.Properties["displayName"].Value;
                          this.FirstName = (string)entry.Properties["firstName"].Value;
                          this.MiddleName = (string)entry.Properties["middleName"].Value;
                          this.LastName = (string)entry.Properties["lastName"].Value;
                  
                          //Section: Address
                          this.StreetAddress = (string)entry.Properties["streetAddress"].Value;
                          this.City = (string)entry.Properties["city"].Value;
                          this.State = (string)entry.Properties["state"].Value;
                          this.PostalCode = (string)entry.Properties["postalCode"].Value;
                          this.TelephoneNumber = (string)entry.Properties["telephoneNumber"].Value;
                      }
                  
                      public string DisplayName
                      {
                          get;
                          private set;
                      }
                  
                      public string Mail
                      {
                          get;
                          private set;
                      }
                  
                      public string sAMAccountName
                      {
                          get;
                          private set;
                      }
                  
                      public string Description
                      {
                          get;
                          private set;
                      }
                  
                      public string Company
                      {
                          get;
                          private set;
                      }
                  
                      public string Title
                      {
                          get;
                          private set;
                      }
                  
                      public string Department
                      {
                          get;
                          private set;
                      }
                  
                      public string FirstName
                      {
                          get;
                          private set;
                      }
                  
                      public string MiddleName
                      {
                          get;
                          private set;
                      }
                  
                      public string LastName
                      {
                          get;
                          private set;
                      }
                  
                      public string StreetAddress
                      {
                          get;
                          private set;
                      }
                  
                      public string City
                      {
                          get;
                          private set;
                      }
                  
                      public string State
                      {
                          get;
                          private set;
                      }
                  
                      public string PostalCode
                      {
                          get;
                          private set;
                      }
                  
                      public string TelephoneNumber
                      {
                          get;
                          private set;
                      }
                  }
                  

                  推荐答案

                  查询全局目录才是正确的做法.

                  Querying the global catalog is the correct approach.

                  您可能想要查看不明确的名称解析 (ANR) - http://support.microsoft.com/kb/243299.

                  You might want to look into Ambigous Name Resolution (ANR) - http://support.microsoft.com/kb/243299.

                  这篇关于如何使用 C# 更好地查询 Active Directory 中的多个域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  How delegates work (in the background)?(代表如何工作(在后台)?)
                  C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                    <tbody id='NtmvH'></tbody>
                2. <legend id='NtmvH'><style id='NtmvH'><dir id='NtmvH'><q id='NtmvH'></q></dir></style></legend>

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

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