Click here to Skip to main content
15,881,757 members
Articles / Programming Languages / C#
Tip/Trick

Accessing ADS User's

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
4 Jun 2013CPOL 6.5K   4  
How to access Active Director users on a WinNT network and show them in a dropdown list.

Introduction

This article explains how to access Active Directory users on a WinNT Network and show them in a dropdown list.

Background

We have many small ASP.NET applications in my firm that all have their own Forms Authentication and authorization, so managing the users for each application has become complex. I decided to bring all the applications into one portal like application and use ADS for authentication but application wise - Role Wise Authorization. It was pretty simple and straight for authentication but using an Oracle database was a bit challenging. Here I m not going to put the whole application if required or if demanded by people.

Using the code 

It is just for understanding and as a start up for accessing ADS records

C#
using System.DirectoryServices; 

private IEnumerable<string> GetADSUserList(string strLDAP)
{
   
    DirectoryEntry directoryEntry = new DirectoryEntry(strLDAP);
    List<string> usernames = new List<string>();
    
    foreach (DirectoryEntry child in directoryEntry.Children)
    {
        if (child.SchemaClassName == "User")
        {
            usernames.Add(child.Name.ToString());
        }
    }
    return usernames;
}

protected void Page_Load(object sender, EventArgs e)
{
    DropDownList1.DataSource = GetADSUserList("WinNT://xyz.com");
    DropDownList1.DataBind();
}

Hope this will be a good point to start.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --