aspnet core get current user id code example
Example 1: asp.net core identity get user id
public async Task<IActionResult> YourMethodName()
{
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier)
var userName = User.FindFirstValue(ClaimTypes.Name)
ApplicationUser applicationUser = await _userManager.GetUserAsync(User);
string userEmail = applicationUser?.Email;
}
Example 2: dotnet core 3.1 get the user that just logged in
private Task<ApplicationUser> GetCurrentUserAsync() => _userManager.GetUserAsync(HttpContext.User);