Click here to Skip to main content
Click here to Skip to main content

Accessing ADS User's

, 4 Jun 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

V R Shukla
Technical Lead
India India
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141220.1 | Last Updated 4 Jun 2013
Article Copyright 2013 by V R Shukla
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid