How To Get Current User Claims In ASP.NET Identity

In this blog, you will learn how to Get Current User Claims In ASP.NET Identity.

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.
  1. ClaimsPrincipal.Current.Identities.First().Claims.ToList(); 
If you want to get specific claim from claim list then the following code snippet will be used.
  1. //First get user claims    
  2. var claims = ClaimsPrincipal.Current.Identities.First().Claims.ToList();    
  4. //Filter specific claim    
  5. claims?.FirstOrDefault(x => x.Type.Equals("UserName", StringComparison.OrdinalIgnoreCase))?.Value   
Detailed tutorials