Richard Gadsden
Richard Gadsden

Reputation: 849

Getting user's display name from WindowsIdentity

I'm in a ASP.NET application using Windows Authentication.

I'm using HttpContext.Current.User.Identity.Name to get the username of the currently authenticated user, which gets me a username in the format DOMAIN\USERNAME. This is working fine.

Is there an easy way to convert this to a display name (e.g. "Richard Gadsden") like the one that appears on the top of my start menu in XP?

If I have to, I guess I can go through System.DirectoryServices and query into ADSI, but surely there's an easier way?

Upvotes: 13

Views: 11016

Answers (3)

Joel Tipke
Joel Tipke

Reputation: 488

There is an easier way now, use System.DirectoryServices.AccountManagement

Imports System.DirectoryServices.AccountManagement

...

   Dim CurrentUser As UserPrincipal = UserPrincipal.Current
   Dim DisplayName As String = CurrentUser.DisplayName 

Upvotes: 14

Wayne Hartman
Wayne Hartman

Reputation: 18477

Here's a tutorial on just how to do that:

http://www.youcanlearnseries.com/Programming%20Tips/CSharp/LDAPReader.aspx

Upvotes: 1

Mehrdad Afshari
Mehrdad Afshari

Reputation: 421998

I guess ADSI is the way to go. It's pretty easy. I don't see an easier way. You just query for LDAP://<SID=user-sid> and get the distinguished name property.

Upvotes: 1

Related Questions