How to get the current logged in user ID in ASP.NET 5?
Last modified: July 18, 2021private readonly UserManager<IdentityUser> _userManager;
public HomeController(UserManager<IdentityUser> userManager)
{
_userManager = userManager;
}
public async Task<IActionResult> Index()
{
var user = await _userManager.GetUserAsync(User);
var userId = user.Id;
var username = user.UserName;
return View();
}