【问题标题】:DirectorySearcher.FindAll gets stuckDirectorySearcher.FindAll 卡住
【发布时间】:2014-10-16 13:34:26
【问题描述】:

我正在尝试从 Active Directory 中获取所有用户。

private void Form1_Load(object sender, EventArgs e)
{
    string[] RetProps = new string[] { "SamAccountName", "DisplayName" };
    List<string[]> users = new List<string[]>();

    foreach (SearchResult User in GetAllUsers("localhost", RetProps))
    {
        DirectoryEntry DE = User.GetDirectoryEntry();
        try
        {
            users.Add(new string[] { DE.Properties["SamAccountName"][0].ToString(), DE.Properties["DisplayName"][0].ToString() });
        }
        catch
        {
        }
    }
}

internal static SearchResultCollection GetAllUsers(string DomainName, string[] Properties)
{
    DirectoryEntry DE = new DirectoryEntry("LDAP://" + DomainName);
    string Filter = "(&(objectCategory=organizationalPerson)(objectClass=User))";
    DirectorySearcher DS = new DirectorySearcher(DE);
    DS.PageSize = 10000;
    DS.SizeLimit = 10000;
    DS.SearchScope = SearchScope.Subtree;
    DS.PropertiesToLoad.AddRange(Properties); DS.Filter = Filter;
    SearchResultCollection RetObjects = DS.FindAll();
    return RetObjects;
 }

但是在到达GetAllUsers 函数中的DS.FindAll(); 时,它会卡住。

【问题讨论】:

    标签: c# active-directory directoryservices


    【解决方案1】:

    问题是我没有在(调试->异常)中启用“公共语言运行时异常”。 DS.FindAll() 除外;有运行时,所以它停止执行剩余的代码。

    【讨论】:

      猜你喜欢
      • 2013-02-26
      • 2017-12-29
      • 2011-08-04
      • 2011-11-17
      • 2014-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多