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);
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);
You need get user user information from user manager:
string username = HttpContext.Current.GetOwinContext()
.GetUserManager<ApplicationUserManager>().FindById(ID).UserName;
string username=... insteadvar automatically determines the type of the variable by what's being assigned to it, so in this case, username would be of type string.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.
An exception of type 'System.ArgumentException' occurred in System.Web.dll but was not handled in user code Additional information: The provider user key supplied is invalid. It must be of type System.GuidUnable to connect to SQL Server database. when I using follwing code string duser = Membership.GetUser(userID).UserName; //first get the User id by calling user.idetntity
var user = User.Identity.GetUserId();
//appuser
ApplicationUser appUser = new ApplicationUser();
appUser = db.Users.Find(user);
//get the user name
var Name= appUser.UserName;