ASP.NET Identity need help getting to respective logged in user's row in AspNetUsers table
Hello all,
What the title says, I need to know how to get to that row. Here's what I've tried already from the internet:
Help?
4 Replies
Try going from
ClaimsPrincipal
?
It will be injected by default into controllers and pages as User
property
So User.FindFirstValue(ClaimTypes.NameIdentifier)
would give you the user ID
In general, that .FindFirstValue()
is how you would get any claim
I have a number of useful extension methods to simplify it, for example
GetNumericId is the same it just casts into a long value, right?
I mean, you can see what it does
Identity stores the IDs as strings, by default
And since I set it to use longs for sequential IDs, I need to parse that
If your IDs are strings, keep it as-is
If they're GUIDs, you might need to parse the strings to a GUID instead of a long
Etc
thanks, it works ❤️
yeah, I just don't understand very well what claims are or how they work