C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How To Get Current User Claims In ASP.NET Identity
WhatsApp
Faisal Pathan
5y
363.7
k
0
4
25
Blog
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.
//First get user claims
var claims = ClaimsPrincipal.Current.Identities.First().Claims.ToList();
//Filter specific claim
claims?.FirstOrDefault(x => x.Type.Equals(
"UserName"
, StringComparison.OrdinalIgnoreCase))?.Value
Detailed tutorials
Introduction To ASP.NET Identity
Create Identity In Simple Ways Using ASP.NET MVC 5
Get Current User Claims
Identity
Get Current User Claims In ASP.NET Identity
People also reading
Membership not found