Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting user's display name from WindowsIdentity

Tags:

asp.net

vb.net

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?

like image 839
Richard Gadsden Avatar asked May 19 '09 15:05

Richard Gadsden


3 Answers

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 
like image 176
Joel Tipke Avatar answered Nov 08 '22 08:11

Joel Tipke


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

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

like image 2
Wayne Hartman Avatar answered Nov 08 '22 08:11

Wayne Hartman


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.

like image 1
mmx Avatar answered Nov 08 '22 07:11

mmx