var userIdentity = HttpContext.User.Identity as ClaimsIdentity; if (userIdentity != null) { var emailClaim = userIdentity.FindFirstValue("email"); if (emailClaim != null) { // Perform action with email value } }
private string GetRoleId(ClaimsPrincipal user) { return user?.FindFirstValue(ClaimTypes.Role); }In this example, we are extracting the Role claim value for a given user by using the FindFirstValue method. The package library for this method is System.Security.Claims.