2
Answers

How to get custom claims in asp.net core?

Karan Thakkar

Karan Thakkar

5y
12.4k
1
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)