1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...
Email Email

Active Directory Searching with ASP.Net

Whenever I’ve Googled for and Visual Basic or C# code which will allow me to search through Active Directory I’ve had no luck. So, I wrote my own.

There are 2 parts to this project:

  • A User Class which defines all of the properties related to AD.
  • An Active Directory class which searches AD and creates an collection list made up of user objects which can then be bound to a Gridview or used as an object elsewhere.

There a number of functions in my Active Directory class such as find users by Groups, list all users in an AD group, select a single user from the list, etc. It could quite easily be expanded to meet your needs.

Below is a screen shot where I have implemented a Web Page which just allows for basic searching. You choose the AD property you want to search against and the results are displayed in a Gridview.

Download: Active Directory Class - Downloaded 295 Times

UPDATE: I missed out the ‘directReports’ property in Active Directory. To make use of this you need to add a new collection to the User class and populate it with a user objects.

e.g.

In User Class:


private _directReports as collection    

public property directReports as collection
get
return _directReports
end get
set (byVal value as collection)
_directReports = value
end set
end property

In AD Class: (In the same way as groups work)


For index as integer 0 to oResults.properties("directReports").count - 1    

dim staff as new user
staff.username = extractName(oResults.properties("directReports").item(index))

oUser.directReports.add(staff)

next

Download Active Directory Class Version 1.0

Downloaded a total of 295 times

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google

About the Author

Nick

I'm Nick Allport, Web Developer out of South Wales, UK. These are my Ramblings, Thoughts and Stuff about all sorts of things. See what I did there?

7 Responses to “ Active Directory Searching with ASP.Net ”

  1. Thenx Bro Thanke u sooooooooo much

  2. is there any way to get the user password…

  3. I read similar article also named e Directory Searching with ASP.Net, and it was completely different. Personally, I agree with you more, because this article makes a little bit more sense for me

  4. @Mohsin

    Sorry for the late reply. I’ve been on holiday.

    I presume that if you wanted to get user password then you just need to find out what the LDAP property is.

    Then you would need to create a new Public Property for User.vb and add the following to AD.vb.

    search.PropertiesToLoad.Add("PASSWORD_PROPERTY")

    I strongly suspect that you will find that passwords are encrypted though.

  5. Pretty nice site, wants to see much more on it! :)t

  6. Excellent Nick.

    I have downloaded the above code. How do I create a connection to an Active Directory server?

    I know we need to create DirectoryEntry(”LDAP://…”). Any ideas on how to do this and where to have this in the code?

    Just want to test this on a live active directory.

  7. @Erz

    Thanks for the comments. On my network the code just connects automatically to Active Directory so just try it and see. The only reason you would need to introduce a connection string would be if you want to use a Proxy Account to access AD.

Leave a Reply

You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>