Karan Thakkar

Karan Thakkar

  • 1.2k
  • 204
  • 90k

How to get custom claims in asp.net core?

Aug 14 2019 5:13 AM
var claims = new List<Claim>
{
new Claim(ClaimTypes.Name, user.UserNm),
new Claim(ClaimTypes.Role, user.UserRole),
new Claim(ClaimTypes.NameIdentifier, user.LoginId),
new Claim("Email", user.EmailId)
};
 
--I have created above claims, in that I have a custom claim which is Email Id I want to fetch that data inside my user object how can I achieve it and also Role.
 
User user = new User();
System.Security.Claims.ClaimsPrincipal currentUser = this.User;
user.UserNm = User.Identity.Name;
user.UserRole=?
 
Big thanks in advance if anyone can help me.

Answers (2)