Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Accessing ADS User's

0.00/5 (No votes)
4 Jun 2013 1  
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

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here