?
Solved

Active Directory - basics to pull up user info

Posted on 2007-11-20
1
Medium Priority
?
871 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
DavidTMoore earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

649 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