Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

With the least effort how to find out Username in Asp.Net MVC

try following code and seems like not working

 string Username = User.Identity.GetUserName(Id);
like image 629
Chathz Avatar asked Aug 28 '15 11:08

Chathz


2 Answers

You need get user user information from user manager:

string username = HttpContext.Current.GetOwinContext()
    .GetUserManager<ApplicationUserManager>().FindById(ID).UserName;
like image 140
Sam FarajpourGhamari Avatar answered Sep 21 '22 19:09

Sam FarajpourGhamari


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

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

userId is the Guid primary key of the user.

like image 22
user1666620 Avatar answered Sep 22 '22 19:09

user1666620