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

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

      1. 从 NT 域名推断 LDAP 地址

        Inferring LDAP address from NT domain name(从 NT 域名推断 LDAP 地址)
              <tbody id='aOqOW'></tbody>
              <tfoot id='aOqOW'></tfoot>
                <legend id='aOqOW'><style id='aOqOW'><dir id='aOqOW'><q id='aOqOW'></q></dir></style></legend>

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

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

                  本文介绍了从 NT 域名推断 LDAP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  给定一个 NT 风格的帐户名称 (DOMAINUserName) 是否可以推断出该域的 LDAP 地址是什么,以便可以查找用户信息?

                  Given a NT style account name (DOMAINUserName) is it possible to infer what the LDAP address for that domain is so that user info can be looked up?

                  我的场景:我有一个在 IIS 上运行的 asp.net 应用程序,它接受匿名用户和域用户.匿名用户必须登录,但域用户我检查服务器标头以获取 IIS 提供的域用户名.我需要从活动目录中查找一些信息,例如电子邮件地址等.如果我在配置中提供 LDAP 地址,我就可以完成这项工作,但如果可以避免的话,我宁愿不必维护这个额外的配置值.

                  My scenario: I have an asp.net app running on IIS that accepts both anonymous and domain users. The anonymous users have to sign in but the domain users I check the server headers for the domain user name provided by IIS. I need to look up some info from active directory like email address etc. I have got this working if I supply the LDAP address in config but would prefer not to have to maintain this extra config value if I can avoid it.

                  推荐答案

                  如果所有域都属于同一个林,您应该能够执行全局目录搜索(GC://而不是 LDAP://).您只能获得部分属性设置,但您可以获取 DistinguishedName,然后进行标准 LDAP://查找.

                  If all of the domains are part of the same forest, you should be able to do a global catalog seach (GC:// instead of LDAP://). You only get a partial attribute set back but you can get the distinguishedName and then to a standard LDAP:// lookup.

                  如果您的不同域位于不同的森林中,那么一种简单的方法是构建您的 NetBIOS 域名的查找表.对于每个林,您使用 (netBIOSname=*) 过滤器对 CN=Partitions,CN=Configuration,DC=YourDomain,DC=com 进行子树搜索,您将获得该林中域的列表.dnsRoot 属性将为您提供域的 DNS 名称,您可以使用它来绑定,或者对其进行 DNS 查找并使用您绑定的第一个地址.或者您可以使用 dnsRoot 创建 System.DirectoryServices.ActiveDirectory.DirectoryContext 以使用 DirectoryServer 的 DirectoryContextType 来获取对域控制器的引用.或者您可以使用 nCName(为您提供域的命名上下文).

                  If you're in the situation where you have different domains that are in different forests, then one simple way would be to build a look-up table of your NetBIOS domain names. For each forest, you do a subtree search of CN=Partitions,CN=Configuration,DC=YourDomain,DC=com with a filter of (netBIOSname=*) and you'll get back a list of the domains in that forest. The dnsRoot attribute will give you the DNS name of the domain and you can just use that to bind to, or do a DNS lookup of it and use the first address you get to bind to. Or you can use the dnsRoot to create System.DirectoryServices.ActiveDirectory.DirectoryContext to with a DirectoryContextType of DirectoryServer to get you a reference to the domain controller. Or you could use nCName (gives you the namingContext of the domain).

                  如果您能提供更多详细信息,或者其中有任何不清楚的地方,我可能会提供更多帮助.

                  I can probably help more, if you can provide more details, or if any of that wasn't clear.

                  补充:

                  1. 您可以通过提供目录中对象的 distinctName 来执行无服务器绑定"来获取 DirectoryEntry.例如.LDAP://CN=User1,CN=Users,DC=yourdomain,DC=com".这将自动发现适当的域控制器并绑定到它以获取对象.
                  2. 如果您使用 DirectorySearcher 进行搜索,并且您没有提供 SearchRoot 对象,它将自动绑定到当前域的根目录.您可以提供 SearchRoot 来缩小搜索范围,但您不必这样做.
                  3. 如果您绝对需要获取当前域的名称,您可以绑定到一个名为 RootDSE ("LDAP://RootDSE") 的对象并获取 defaultNamingContext 属性的值.这将返回DC=yourdomain,DC=com"位.

                  坦率地说,除非您确定需要它,否则更通用的代码可能不值得痛苦,因为它取决于您的域和森林的结构.例如.如果您有两个森林,它们之间是否存在信任:在您有两个森林之前您不会知道这一点,并且解决方案将取决于此.敏捷开发中有一条精辟的小格言让我无法理解,但它的思路是不要编写你现在不需要的代码.

                  Frankly, more general code is probably not worth the pain unless you're sure you're going to need it because it will be dependent on the structure of your domains and forests. E.g. if you have two forests, is there a trust between them: you won't know this until you have two forests and the solution will depend on this. There's a pithy little maxim in agile development which escapes me but it goes along the lines of don't code what you don't need now.

                  这是一个执行此类搜索的控制台程序:

                  Here's a console program that will perform such a search:

                  using System;
                  using System.Collections.Generic;
                  using System.Linq;
                  using System.Text;
                  using System.DirectoryServices;
                  
                  namespace SearchDirectory
                  {
                      class Program
                      {
                          static void Main(string[] args)
                          {
                              string user = @"YOURDOMAINyourid";
                  
                              using (DirectorySearcher ds = new DirectorySearcher())
                              {
                                  ds.SearchScope = SearchScope.Subtree;
                                  ds.Filter = String.Format("(&(objectClass=user)(objectCategory=person)(sAMAccountName={0}))",
                                      user.Split('\')[1]);
                                  ds.PageSize = 1000;
                                  using (SearchResultCollection src = ds.FindAll())
                                  {
                                      foreach (SearchResult sr in src)
                                          Console.WriteLine(sr.Properties["distinguishedName"][0].ToString());
                                  }
                              }
                  
                              Console.WriteLine("
                  Press a key to continue...");
                              Console.ReadKey(true);
                          }
                      }
                  }
                  

                  我在这方面做了一些改进,但它应该可以帮助您入门.我的建议是让它在控制台程序中运行,然后将该类移动到您的 ASP.NET 项目中.System.DirectoryServices 可能会抛出很多奇怪的错误,并且在 ASP.NET 中使用 S.DS 也很有趣,因此最好在将代码封装到所有 ASP.NET 中之前了解它是否有效.

                  I've cut some corners on this but it should get you started. My advice is to get it working in a console program and then move the class to your ASP.NET project. There are plenty of odd errors System.DirectoryServices can throw you and using S.DS inside of ASP.NET can be fun too so it's best to know your code works before you wrap it in all of that ASP.NET loveliness.

                  这篇关于从 NT 域名推断 LDAP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Adding and removing users from Active Directory groups in .NET(在 .NET 中的 Active Directory 组中添加和删除用户)
                  How do you determine if two HashSets are equal (by value, not by reference)?(您如何确定两个 HashSet 是否相等(按值,而不是按引用)?)
                  Is there a quot;Setquot; data structure in .Net?(有没有“套路?.Net 中的数据结构?)
                  Collection that allows only unique items in .NET?(仅允许 .NET 中唯一项目的集合?)
                  Adding headers in ASP.NET MVC 3(在 ASP.NET MVC 3 中添加标头)
                  Response.Redirect strips Header Referrer - Possible to Add it Back?(Response.Redirect 剥离 Header Referrer - 可以将其添加回来吗?)
                  • <legend id='4AnR4'><style id='4AnR4'><dir id='4AnR4'><q id='4AnR4'></q></dir></style></legend>
                  • <small id='4AnR4'></small><noframes id='4AnR4'>

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

                            <tbody id='4AnR4'></tbody>
                            <bdo id='4AnR4'></bdo><ul id='4AnR4'></ul>
                            <tfoot id='4AnR4'></tfoot>