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?
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
Here's a tutorial on just how to do that:
http://www.youcanlearnseries.com/Programming%20Tips/CSharp/LDAPReader.aspx
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With