Problem with Searching Groups in Active Directory

Discussion in 'ASP .Net Security' started by Cathie, Apr 4, 2005.

  1. Cathie

    Cathie Guest

    Hi All,

    I am trying to use DirectorySearch and it is just not working for me. I
    have the following ActiveDirectory structure:

    TestGroup (group)
    -> TestUser (user)
    -> TestAdministrators(group)
    -> Development Team (group)
    -> DevA (user)
    -> DevB (user)
    -> DevC (user)

    Where -> represents "member of "

    I am trying to get the list of Groups and Users from TestGroup which to my
    reckoning should be TestUser and TestAdministrators, but if I use
    SearchScope.SubTree I get "TestGroup" but nothing else, and if I use
    SearchScope.OneLevel I don't get anything.

    What is wrong with this code?

    DirectoryEntry group = new
    DirectoryEntry("LDAP://CN=TestUsers,CN=Users,DC=comp,DC=company,DC=com");
    object members = group.Invoke("Members",null);
    foreach(object member in (IEnumerable) members)
    {
    if (str != String.Empty)
    {
    str += ", ";
    }
    DirectoryEntry x = new DirectoryEntry(member);
    str += x.Name.ToString() + ": " + x.SchemaClassName;
    }

    DirectorySearcher src = new DirectorySearcher(group);
    src.Filter = "(objectClass=*)";
    src.SearchScope = SearchScope.OneLevel;
    SearchResultCollection resultColl = src.FindAll();
    DirectoryEntry result;
    string[,] memberList = new string[resultColl.Count, 2];
    foreach (SearchResult child in resultColl)
    {
    result = child.GetDirectoryEntry();
    memberList[0,0] = result.Name.ToString();
    if (result.SchemaClassName.ToUpper() == "GROUP")
    {
    memberList[0,1] = "GROUP";
    }
    else if (result.SchemaClassName.ToUpper() == "USER")
    {
    memberList[0,1] = "USER";
    }
    }

    Note: The "members" call gets back what I want, but I believe there is
    issues with this with large numbers of users so was trying to do this the
    right way.

    Thanks in advanced,
    Cathie
     
    Cathie, Apr 4, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott
    Replies:
    2
    Views:
    2,594
    Juan T. Llibre
    May 16, 2006
  2. rote
    Replies:
    2
    Views:
    490
  3. L Magarian
    Replies:
    3
    Views:
    231
    Joe Kaplan \(MVP - ADSI\)
    Sep 28, 2004
  4. Craig Vedur
    Replies:
    5
    Views:
    673
  5. David
    Replies:
    14
    Views:
    858
    Patrick.O.Ige
    Nov 4, 2005
Loading...

Share This Page