Solved

Active Directory - basics to pull up user info

Posted on 2007-11-20
1
865 Views
Last Modified: 2008-02-01
Hello Experts,

I know a bit about asp.net programming, but I know basically nothing about active directory.  I've tried looking this up online, but haven't had any success.  Could someone post a snippet of code that would lets say display all users?

Thanks,
GRCHELPDESK
0
Comment
Question by:GRCHELPDESK
1 Comment
 
LVL 4

Accepted Solution

by:
DavidTMoore earned 500 total points
ID: 20322886
This might not be exactly what you are looking for, but these are the methods I use to interact with active directory, take a look and maybe they can give you a better understanding of how some of this works.
public static DirectoryEntry GetDirectoryEntry()

    {

        DirectoryEntry de = new DirectoryEntry("LDAP://19dc01", "USERNAME", "PASSWORD");

        return de;

    }
 
 

    public bool UserExists(string username)

    {

        DirectoryEntry de = GetDirectoryEntry();

        DirectorySearcher deSearch = new DirectorySearcher();
 

        deSearch.SearchRoot = de;

        deSearch.Filter = "(&(objectClass=user) (cn=" + username + "))";
 

        SearchResultCollection results = deSearch.FindAll();
 

        return results.Count > 0;

    }
 

    public String GetProperty(String userAccount, String propertyName)

    {

        DirectoryEntry entry = GetDirectoryEntry();

        String account = userAccount.Replace(@"DOMAIN\", "");
 

        try

        {

            DirectorySearcher search = new DirectorySearcher(entry);

            search.Filter = "(SAMAccountName=" + account + ")";

            search.PropertiesToLoad.Add(propertyName);
 

            SearchResult result = search.FindOne();
 

            if (result != null)

            {

                return result.Properties[propertyName][0].ToString();

            }

            else

            {

                return "Unknown User";

            }

        }

        catch (Exception ex)

        {

            string debug = ex.Message;

            return "";

        }

    }

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
dynamic menu in asp.net c# 11 57
How do ASP.NET and MVC work together? 4 25
Runtime Exceptions when trying to submit data 28 36
Error in JQuery 5 35
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now