I managed to do ASP.NET authentication work wih AD. Now, I want to query an OU in AD and display the result
either ListView or GridView in ASP.NET page.
Here’s the Domain Controller: dc.itlab.edu
The OU: UsersStudents
In the organizational unit (OU) UsersStudents there are following columns:
First Name, Last Name, Pre-Windows 2000 Logon Name, Name , Type
I want to query column First Name, Last Name, Pre-Windows 2000 Logon Name in OU UsersStudents and bind the
result to ListView or GridView.
Thank you for suggestion either in C# or VB.NET.
If you are on .NET 3.5, or could upgrade to it – the LDAP stuff has been vastly improved with the introduction of the
System.DirectoryServices.AccountManagementnamespace.It contains among other things classes like
UserPrincipal, which offers most of the commonly used LDAP attributes as properties. Using thePrincipalSearcherand QBE (Query-by-example), you could very easily find those users (or other objects) you’re interested in and binding them to the ASP.NET grid view.To learn more about the new .NET 3.5 stuff, read this excellent article at MSDN Magazine:
Managing Directory Security Principals in the .NET Framework 3.5 – January 2008 issue
Update: Using the .NET 3.5 interface, you can write code something like this:
Now you should be able to bind the
resultsdirectly to aDataGridViewor something, and pick out those properties for your columns that you’re looking for: