Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 240335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:39:29+00:00 2026-05-11T20:39:29+00:00

I’ve got an asp application running but i want to search the Active Directory.

  • 0

I’ve got an asp application running but i want to search the Active Directory.

i am using vb (visual web developer 2008)

how do i search the active directory for a given user?

ie: user enters login name in text box, clicks submit. active directory is searched on-click for this user. when found user information is displayed .

Thanks

  • 1 1 Answer
  • 4 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:39:29+00:00Added an answer on May 11, 2026 at 8:39 pm

    What version of the .NET framework can you use? Searching and looking up stuff in AD has become extremely easy in .NET 3.5 – see this great MSDN article by Ethan Wilanski and Joe Kaplan on using the security principals API for that.

    If you’re not on .NET 3.5 yet, you’ll have to use the DirectorySearcher class and set up the search filters as you need. Getting the LDAP filter right is probably the biggest obstacle.

    Robbie Allen also has two great intro article on System.DirectoryServices programming:
    – Part 1
    – Part 2

    There are some really good resources at http://www.directoryprogramming.net (Joe Kaplan’s site – he’s a Microsoft Active Directory MVP), and Richard Mueller has some great reference excel sheets on what properties are available for each of the ADSI providers, and what they mean, and how their LDAP name is – see http://www.rlmueller.net.

    Marc

    EDIT: Ok- here’s the .NET 2.0 / 3.0 approach:

    // set the search root - the AD container to search from
    DirectoryEntry searchRoot = new DirectoryEntry("LDAP://dc=yourdomain,dc=com");
    
    // create directory searcher
    DirectorySearcher ds = new DirectorySearcher(searchRoot);
    
    ds.SearchScope = SearchScope.Subtree;
    
    // set the properties to load in the search results
    // the fewer you load, the better your performance    
    ds.PropertiesToLoad.Add("cn");
    ds.PropertiesToLoad.Add("sn");
    ds.PropertiesToLoad.Add("givenName");
    ds.PropertiesToLoad.Add("mail");
    
    // set the filter - here I'm using objectCategory since this attribute is
    // single-valued and indexed --> much better than objectClass in performance
    // the "anr" is the "ambiguous name resolution" property which basically
    // searches for all normally interesting name properties
    ds.Filter = "(&(objectCategory=person)(anr=user-name-here))";
    
    // get the result collection
    SearchResultCollection src = ds.FindAll();
    
    // iterate over the results
    foreach (SearchResult sr in src)
    {
        // do whatever you need to do with the search result
        // I'm extracting the properties I specified in the PropertiesToLoad
        // mind you - a property might not be set in AD and thus would
        // be NULL here (e.g. not included in the Properties collection)
        // also, all result properties are really multi-valued, so you need
        // to do this trickery to get the first of the values returned
        string surname = string.Empty;
        if (sr.Properties.Contains("sn"))
        {
            surname = sr.Properties["sn"][0].ToString();
        }
    
        string givenName = string.Empty;
        if (sr.Properties.Contains("givenName"))
        {
            givenName = sr.Properties["givenName"][0].ToString();
        }
    
        string email = string.Empty;
        if (sr.Properties.Contains("mail"))
        {
            email = sr.Properties["mail"][0].ToString();
        }
    
        Console.WriteLine("Name: {0} {1} / Mail: {2}", givenName, surname, email);
     }
    

    Hope this helps!

    Marc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I want to count how many characters a certain string has in PHP, but
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
This could be a duplicate question, but I have no idea what search terms
I want to construct a data frame in an Rcpp function, but when I
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.