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

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

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

      1. <tfoot id='bHqcs'></tfoot>

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

        使用 C# 获取活动目录用户数据

        时间:2023-10-24
        • <bdo id='Dt0yb'></bdo><ul id='Dt0yb'></ul>

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

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

                • <legend id='Dt0yb'><style id='Dt0yb'><dir id='Dt0yb'><q id='Dt0yb'></q></dir></style></legend>
                    <tbody id='Dt0yb'></tbody>
                  本文介绍了使用 C# 获取活动目录用户数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想获取有关特定用户的数据.我知道该用户的 OU 路径,但无法使用该 OU 路径获取信息.它总是说找不到用户.谁能告诉我我需要更改搜索过滤器吗?请帮忙 .

                  I want to fetch data about particular user . I know the OU path of this user but I can't fetch info using that OU path . It always says that user is not found . Can anyone tell me that do I need to change search filter . Please help .

                  代码

                  用户的路径 abc.ds.xyz.net/fGroup/xcxc/Users/123456abc.ds.xyz.net 是 domain 那么 fGroup 是 OU , xcxc 是 OU , Users 是 OU , 123456 是 cn .

                  path of the user abc.ds.xyz.net/fGroup/xcxc/Users/123456 abc.ds.xyz.net is domain then fGroup is OU , xcxc is OU , Users is OU , 123456 is cn .

                      using System;
                      using System.Collections.Generic;
                      using System.Linq;
                      using System.Text;
                      using System.Threading.Tasks;
                      using System.DirectoryServices;
                      using System.DirectoryServices.AccountManagement;
                      using System.Web.UI.WebControls;
                      using System.Data;
                      using System.Drawing;
                      using System.Windows.Forms;
                  
                      namespace Ldap_authentication
                      {
                         public class Program
                         {
                           static void Main(string[] args)
                           {
                  
                              Console.Write("Enter user: ");
                              String username = Console.ReadLine();
                  
                              try
                              {
                                DirectoryEntry myLdapConnection = createDirectoryEntry();
                  
                                DirectorySearcher search = new DirectorySearcher(myLdapConnection);
                                search.Filter = "(&(OU=fGroup)(OU=xcxc )(OU=Users)(cn=" + username + "))";
                                SearchResult result = search.FindOne();
                  
                                if (result != null)
                                {
                  
                                  ResultPropertyCollection fields = result.Properties;
                  
                                  foreach (String ldapField in fields.PropertyNames)
                                  {
                  
                                      foreach (Object myCollection in fields[ldapField])
                                          Console.WriteLine(String.Format("{0,-20} : {1}",
                                                        ldapField, myCollection.ToString  ()));
                                  }
                               }
                  
                               else
                               {
                                  // user does not exist  
                                  Console.WriteLine("User not found!");
                                  Console.ReadLine();
                               }
                           }
                  
                          catch (Exception e)
                          {
                              Console.WriteLine("Exception caught:
                  
                  " + e.ToString());
                               Console.ReadLine();
                          }
                  
                  
                      }
                      static DirectoryEntry createDirectoryEntry()
                      {
                          DirectoryEntry ldapConnection = new DirectoryEntry("abc.ds.xyz.net");
                          ldapConnection.Path = "LDAP://DC=abc,DC=ds,DC=xyz,DC=net";
                          ldapConnection.AuthenticationType = AuthenticationTypes.Secure;
                          return ldapConnection;
                      }
                     }
                    }
                  

                  编辑

                      search.Filter = "(&(OU=fGroup))";
                      SearchResult result = search.FindOne();
                  

                  当我更改 search.Filter = "(&(OU=fGroup)(OU=xcxc )(OU=Users)(cn=" + username + "))";进入 search.Filter = "(&(OU=fGroup))";我得到结果.谁能告诉我如何使用多个搜索输入过滤器进行搜索.

                  when I change search.Filter = "(&(OU=fGroup)(OU=xcxc )(OU=Users)(cn=" + username + "))"; into search.Filter = "(&(OU=fGroup))"; I get result . Can anyone tell me how to search with multiple search input filter .

                  推荐答案

                  在我的头撞墙几个小时后,我终于找到了答案.我需要编写多个搜索过滤器,例如

                  After hitting my head against a wall for hours and hours finally I found answer . I need to write multiple search filters like

                  旧代码搜索.Filter = "(&(OU=fGroup))";用这个替换它

                  Old code search.Filter = "(&(OU=fGroup))"; replace this with this

                     search.Filter = "(&(OU=fGroup))";
                     search.Filter = "(&(OU=xcxc))";
                     search.Filter = "(&(OU=Users))";
                     search.Filter = "(&(cn=" + username + "))";
                     SearchResult result = search.FindOne();
                  
                     Finally found my answer :) . Happy Coding guys :)
                  

                  这篇关于使用 C# 获取活动目录用户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么使用 DirectoryEntry 对 LDAP 进行身份验证会间歇性地抛出 COMException (0x80 下一篇:将 StartTLS 与 System.DirectoryServices 中的 LDAP 结合使用

                  相关文章

                • <tfoot id='FU3jX'></tfoot>

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