selvi jp

selvi jp

  • NA
  • 323
  • 78.9k

User.Identity.GetUserId() returns null in core api

Jun 9 2021 7:08 AM

User.Identity.GetUserId() returns null.i am tring all this get id method.but I get null

ClaimsPrincipal currentUser = this.User;
var currentUserName = currentUser.FindFirst(ClaimTypes.NameIdentifier).Value;
var userzzz =_userManager.FindByNameAsync(currentUserName);
var userIdkkkh =_userManager.GetUserAsync(this.User);
var a=userIdkkkh.Id;
var claimsIdentity = this.User.Identity as ClaimsIdentity;
var userId = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier)?.Value;
string userIdls = _userManager.GetUserId(User);
var userk = _userManager.FindByIdAsync(User.Identity.Name);
string userIdkkk = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
var userIds = User.FindFirstValue(ClaimTypes.NameIdentifier); // will give the user's userId
var userName = User.FindFirstValue(ClaimTypes.Name); // will give the user's userName
var id = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
var userIda = _userManager.GetUserId(HttpContext.User);
var userIdss = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
//ApplicationUser currentUser = _userManager.Users.FirstOrDefault(u => u.Id == User.Identity.GetUserId());
var user= _userManager.FindByIdAsync(User.Identity.GetUserId());
var userIdsss = this.User.FindFirstValue(ClaimTypes.NameIdentifier);


Answers (2)