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

Related Questions

I have a function that looks like this class NSNode { function insertAfter(NSNode $node)
I have a function that checks if a cookie (by name) exists or not:
I have a function that gives me the following warning: [DCC Warning] filename.pas(6939): W1035
I have a function that gets x(a value) and xs(a list) and removes all
I have a function that takes, amongst others, a parameter declared as int privateCount
I have a function that I use called sqlf(), it emulates prepared statements. For
I have a function that is effectively a replacement for print, and I want
I have a function that takes a struct, and I'm trying to store its
I have a function that automatically exports a table into a CSV file, then
I have a function that resembles the one below. I'm not sure how to

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.