简体   繁体   中英

Getting the display name from a domain \ alias combo

Apologies for not knowing the right way to phrase this question.

Given a domain name and an alias, for example CONTOSO\\steveh how can I get the friendly display name for that alias? For example, in Outlook email sent to CONTOSO\\steveh appears as 'Steve Holt'?

If you are using .net 3.5, add references to System.DirectoryServices and System.DirectoryServices.AccountManagement and try this:

        PrincipalContext c = new PrincipalContext(ContextType.Domain,"CONTOSO");
        UserPrincipal principal = UserPrincipal.FindByIdentity(c,"steveh");
        Console.WriteLine(principal.DisplayName);

I can't verify if it works for a domain since I'm running on a standalone machine but it should help you get started.

You can query ActiveDirectory through LDAP I recommend taking a look at this question which has some basic information. You should be able to get a general direction from there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM