Solved

Active Directory - basics to pull up user info

Posted on 2007-11-20
1
864 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

20 Experts available now in Live!

Get 1:1 Help Now