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.