Get username by aspnet.Identity user ID in asp.net mvc

With the least effort, how to find out a username in Asp.Net MVC

try the following code and it doesn't seem to work

 string Username = User.Identity.GetUserName(Id);
+4
source share
2 answers

You need to get user information from the user:

string username = HttpContext.Current.GetOwinContext()
    .GetUserManager<ApplicationUserManager>().FindById(ID).UserName;
+9
source

you can get the username of any member of MembershipUser using the code below:

string userName = Membership.GetUser(userId).UserName;

userId is the main key of the user guid.

+7
source

All Articles