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

  • Home
  • SEARCH
  • 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 6786701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:16:38+00:00 2026-05-26T17:16:38+00:00

I built a test Active Directory server in Window 2008 and I also run

  • 0

I built a test Active Directory server in Window 2008 and I also run the DNS server on it. On my client machine which runs the C# application, I can authenticate the user against the Active directory server using the function below:

public static UserPrincipal GetUserPrincipal(string usrName,string pswd,string domainName)
{
   UserPrincipal usr;
   PrincipalContext ad;

   // Enter Active Directory settings
   ad = new PrincipalContext(ContextType.Domain, domainName,usrName,pswd);

   //search user
   usr = new UserPrincipal(ad);
   usr.SamAccountName = usrName;

   PrincipalSearcher search = new PrincipalSearcher(usr);
   usr = (UserPrincipal)search.FindOne();
   search.Dispose();
   return usr;
}

In a separate logic I tried to retrieve a user back from the server using a user name. I used the functions below:

public static DirectoryEntry CreateDirectoryEntry()
{
   // create AD connection
   DirectoryEntry de = new DirectoryEntry("LDAP://CN=Users,DC=rootforest,DC=com","LDAP","password");
   de.AuthenticationType = AuthenticationTypes.Secure;
   return de;
}

public static ResultPropertyCollection GetUserProperty(string domainName, string usrName)
{
    DirectoryEntry de = CreateDirectoryEntry();
    DirectorySearcher deSearch = new DirectorySearcher();
    deSearch.SearchRoot = de;
    deSearch.Filter = "(SamAccountName=" + usrName + ")";
    SearchResult results = deSearch.FindOne();

    return null;
}

However, I got no response back from the LDAP server at all, not even an exception. Am I missing certain settings on LDAP server, any of you able to see a flaw in my code (pls don’t mind the hard code values, I was testing with this code).

As part of my troubleshooting, I confirmed that I can ping to the rootforest.com from the client machine. I confirmed the user with property samaccountname “LDAP” exists. My path seems to be right because when I go onto the LDAP server and type :

dsquery user -name LDAP*      

I got the following:

CN=LDAP L. LDAP,CN=Users,DC=rootforest,DC=com

Any help would be greatly appreciated, I’ve spent most of my day troubleshooting and researching this little bugger and I think it could be something small which I overlooked.

  • 1 1 Answer
  • 0 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-26T17:16:39+00:00Added an answer on May 26, 2026 at 5:16 pm

    I don’t understand why you’re using the new PrincipalContext / UserPrincipal stuff in your first example, but fall back to the hard to use DirectoryEntry stuff in your second example…. doesn’t really make sense… also: your second function GetUserProperty seems to return null always – typo or not??

    Since you’re on already using the System.DirectoryServices.AccountManagement (S.DS.AM) namespace – use it for your second task, too! Read all about it here:

    • Managing Directory Security Principals in the .NET Framework 3.5
    • MSDN docs on System.DirectoryServices.AccountManagement

    Basically, you can define a domain context and easily find users and/or groups in AD:

    public static ????? GetUserProperty(string domainName, string usrName)
    {
       // set up domain context
       PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
    
       // find a user
       UserPrincipal user = UserPrincipal.FindByIdentity(ctx, usrName);
    
       if(user != null)
       {
          // return what you need to return from your user principal here
       }
       else
       {
           return null;
       }
    }
    

    The new S.DS.AM makes it really easy to play around with users and groups in AD:

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

Sidebar

Related Questions

I've built a unit test project for a library in VS 2008 C#. The
I'm looking into using Visual Studio 2008's built in unit test projects instead of
I'm using the built in web server in Visual Studio to test some pags
I'm trying to write a C# unit test with VS 2008's built-in unit testing
When I run the following test (built with F#2.0) I get OutOfMemoryException. It takes
Using the new built in testing for Active Record (set Test as the connection
I'm attempting to build a test infrastructure Active Directory + Lync + Exchange. After
Hi I'm trying to run bundle install on my windows machine it runs fine
I've done an adhoc build to test an application, but when I drag it
I'm currently using Team Foundation Server 2008 as a source control and build engine.

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.