0

i am using User.Identity.Name to get User Name.

But in stead of User Name I am getting DomainName\UserID.

I am using Windows Authentication.

Can anybody please suggest any way to get User Name instaed of UserID in windows authentication. C#.

Thank you....

  • similar post with solution you can find here https://stackoverflow.com/questions/16184685/how-do-i-get-the-currently-loggedin-windows-account-from-an-asp-net-page – user9405863 Feb 28 '18 at 09:03

2 Answers2

0

I think you are looking for user display name. Here is way to get it :

using System.DirectoryServices.AccountManagement;
var name = UserPrincipal.Current.DisplayName;

You need to add a reference to System.DirectoryServices.AccountManagement.dll

rahulaga-msft
  • 3,964
  • 6
  • 26
  • 44
-1
logon_user = Request.ServerVariables["LOGON_USER"].Substring(// you domain length here);

e.g : if Domain is "8" character long then,

logon_user = Request.ServerVariables["LOGON_USER"].Substring(8);
Jam Eel Ahmed
  • 79
  • 1
  • 10