We need to use the "System.Security.Claims" namespace to retrieve/get user claims in ASP.NET. Here is a code snippet to get user claims.
- ClaimsPrincipal.Current.Identities.First().Claims.ToList();
If you want to get specific claim from claim list then the following code snippet will be used.
-
- var claims = ClaimsPrincipal.Current.Identities.First().Claims.ToList();
-
-
- claims?.FirstOrDefault(x => x.Type.Equals("UserName", StringComparison.OrdinalIgnoreCase))?.Value
Detailed tutorials