首页 文章

针对Active Directory的身份验证.DirectorySearcher的必要性

提问于
浏览
0

我有以下代码来验证针对Active Directory的给定用户名和密码

DirectoryEntry entryInAbsg = new DirectoryEntry("LDAP://....../DC=....,DC=..", username, password,AuthenticationTypes.Secure);
            object nativeObject = entryInAbsg.NativeObject;
            authenticated = true;

这足以验证用户吗?我需要使用DirectorySearcher再次搜索用户吗?以上用户名和密码应为管理员帐户?

1 回答

  • 0

    这足以验证用户 . 但是要执行搜索,您需要创建DirectorySeacher的实例并将DirectoryEntry对象(entryinAbsg)以及您可能想要的任何过滤器传递给构造函数 . 考虑下面C#中的示例;

    private DirectorySeacher GetDirectorySeacher(DirectoryEntry entryInAbsg)
    {
          DirectorySearcher dirSeach = null;
          if(dirSearch == null)
          {
              try
              {
                  dirSearch = new DirectorySeacher(entryInAbsg)
              }
              catch (DirectoryServicesCOMException e)
              {
                  MessageBox.Show("Authentification Failed!!!, Please Check.", "Error Info", MessageBoxButtons.OK,MessageBoxIcon.Error);
              }
              return dirSearch;
         }
         else
         {
              return dirSearch;
         }
    }
    

    您可以根据您的特定需求进行定制 .

相关问题