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

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

        <tfoot id='rJMJ2'></tfoot>

      1. 如何检查用户是否存在于 LDAP 上

        How to check if a user exists on LDAP(如何检查用户是否存在于 LDAP 上)
          <bdo id='AYiMa'></bdo><ul id='AYiMa'></ul>

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

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

                <tfoot id='AYiMa'></tfoot>
                    <tbody id='AYiMa'></tbody>

                  本文介绍了如何检查用户是否存在于 LDAP 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要仅使用用户名而非密码来验证公司中的用户.

                  I need to verify users in the company using only their username - not their password.

                  所以我需要这样的方法

                  public bool UserExists(string username)
                  { ... }
                  

                  我知道 System.DirectoryServices 命名空间,但不知道从哪里开始.

                  I am aware of the System.DirectoryServices namespace but don't know where to start.

                  有什么想法吗?

                  有 80,000 多条记录,因此请记住这一点.

                  There are 80,000+ records so try to bear that in mind.

                  谢谢.

                  我已经完成了 - 我的代码是:

                  I have done it - my code is:

                  private bool UserExists(string userName, string domain)
                  {
                      try
                      {
                          DirectoryEntry.Exists("WinNT://" + domain + ".[hidden].com/" + userName);
                          return true;
                      }
                      catch (COMException)
                      {
                          return false;
                      }
                  }
                  

                  我不知道它是否正确,但它似乎到目前为止有效.

                  I don't know if it is correct, but it seems to work so far.

                  迈克尔的回答有两个相关部分:

                  Michael's answer has two relevant parts:

                  • http://www.codeproject.com/KB/system/everythingInAD.aspx#22
                  • http://www.codeproject.com/KB/system/everythingInAD.aspx#35

                  更新 #2:

                  我实际使用过这个:

                  public static bool LoggedOnUserExists()
                  {
                      var domain = new PrincipalContext(ContextType.Domain);
                  
                      UserPrincipal foundUser = UserPrincipal.FindByIdentity(domain, IdentityType.SamAccountName, Environment.UserName);
                  
                      return foundUser != null;
                  }
                  

                  推荐答案

                  在 .NET 3.5 及更高版本中,您可以非常简单地使用 System.DirectoryServices.AccountManagement 命名空间:

                  In .NET 3.5 and up, you can use the System.DirectoryServices.AccountManagement namespaces to do this quite simply:

                  public bool UserExists(string username)
                  {
                     // create your domain context
                     using (PrincipalContext domain = new PrincipalContext(ContextType.Domain))
                     {
                         // find the user
                         UserPrincipal foundUser = UserPrincipal.FindByIdentity(domain, IdentityType.Name, username);
                  
                         return foundUser != null;
                      }
                  }
                  

                  这将适用于常规用户名 John Doe,或者您也可以使用用户的电子邮件地址 (john.doe@company.com),或者他的专有名称 (CN=John Doe) - 看看 IdentityType 枚举必须提供什么 :-)

                  This will work with the regular user name John Doe, or alternatively you can use the user's e-mail address (john.doe@company.com), or his distinguished name (CN=John Doe) - see what the IdentityType enumeration has to offer :-)

                  这篇关于如何检查用户是否存在于 LDAP 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Adding and removing users from Active Directory groups in .NET(在 .NET 中的 Active Directory 组中添加和删除用户)
                  set equality in linq(在 linq 中设置相等)
                  HashSet conversion to List(HashSet 转换为 List)
                  How to set timeout for webBrowser navigate event(如何为 webBrowser 导航事件设置超时)
                  Test whether two IEnumerablelt;Tgt; have the same values with the same frequencies(测试两个IEnumerablelt;Tgt;具有相同频率的相同值)
                  How do you determine if two HashSets are equal (by value, not by reference)?(您如何确定两个 HashSet 是否相等(按值,而不是按引用)?)
                  • <bdo id='iGnlS'></bdo><ul id='iGnlS'></ul>
                      <tbody id='iGnlS'></tbody>
                    1. <tfoot id='iGnlS'></tfoot>

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

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