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 163295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:32:32+00:00 2026-05-11T11:32:32+00:00

I have a function that retrieves the fullname of a user based on user

  • 0

I have a function that retrieves the fullname of a user based on user name and domain. This function runs in ASP.NET thread under an impersonated user. When I use Directory searcher on a remote AD branch, I believe I’m getting the SID number instead of the property (cannot verify it occurs on a different box).

public string GetUserFullName(string userName, string domainName) {       DirectoryEntry rootEntry = new DirectoryEntry('GC://dc=company,dc=net');     string filter = string.Format('(&(objectCategory=person)(objectClass=user)(!(userAccountControl:1.2.840.113556.1.4.803:=2))(userPrincipalName={0}@{1}.company.net))', userName, domainName);     DirectorySearcher searcher = new DirectorySearcher(rootEntry, filter, new string[] { 'displayName' });     rootEntry.AuthenticationType = AuthenticationTypes.Secure;     searcher.PageSize = 1000;     searcher.ServerTimeLimit = new TimeSpan(0, 10, 0);     searcher.ReferralChasing = ReferralChasingOption.All;     searcher.Asynchronous = false;      SearchResult result = searcher.FindOne();     if (result != null)     {         return (string) result.Properties['displayName'][0];     }     else     {         throw new Exception('Active Directory could not resolve your user name');     }  } 
  • 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. 2026-05-11T11:32:33+00:00Added an answer on May 11, 2026 at 11:32 am

    What version of the .NET framework are you working against? The AD stuff has been revamped quite extensively in .NET 3.5, and offers strongly typed constructs for User and groups and stuff like that now.

    Check out the excellent article ‘Managing Directory Security Principals in the .NET Framework 3.5‘ by my buddies Joe Kaplan and Ethan Wilansky on MSDN. Excellent stuff indeed.

    First of all, you get a class called UserPrincipal which is strongly typed, e.g. all the basic properties are properties on your object. Very helpful indeed.

    Secondly, you get a nice ‘query-by-example’ method using PrincipalSearcher – check out this sample from Joe and Ethan’s article:

    // create a principal object representation to describe // what will be searched  UserPrincipal user = new UserPrincipal(adPrincipalContext);  // define the properties of the search (this can use wildcards) user.Enabled = false; user.Name = 'user*';  // create a principal searcher for running a search operation PrincipalSearcher pS = new PrincipalSearcher();  // assign the query filter property for the principal object  // you created // you can also pass the user principal in the  // PrincipalSearcher constructor pS.QueryFilter = user;  // run the query PrincipalSearchResult<Principal> results = pS.FindAll();  Console.WriteLine('Disabled accounts starting with a name of 'user':'); foreach (Principal result in results) {     Console.WriteLine('name: {0}', result.Name); } 

    If there’s any chance at all, try to get to .NET 3.5 for your AD stuff !

    Marc

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

Sidebar

Ask A Question

Stats

  • Questions 285k
  • Answers 285k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I remember having this problem before. Cast the value to… May 13, 2026 at 4:44 pm
  • Editorial Team
    Editorial Team added an answer Took the breakpoints out, ran the project in debug mode… May 13, 2026 at 4:44 pm
  • Editorial Team
    Editorial Team added an answer In Firefox and Chrome, 0.1 + 0.2 is 0.30000000000000004, which… May 13, 2026 at 4:44 pm

Related Questions

I've recently added the JQuery autocomplete plug in and have a textbox that autocompletes
My plan is to make a function that retrieves the highest element of an
I am building a real estate website. I have a table for properties (i.e.
Looking for direction and understanding of the approach to implement logic to handle the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.