asp.net core identity claims vs properties (efficiency point of view)

Viewed 1273

i've read all the tutorials and questions asked about the subject but they contradict one another

claims(userclaims and roleclaims) are serialised into a cookie (along with custom identity user properties you specify by overriding the principle factory) but they don't get queried, they're stored in a cookie, which mean that the more claims a user have, the more data will have to round trip between the server and browser

a custom identity user property by default don't get serialised but get queried from the database, so every time you need that data it query it from the database which is more work to do on the database on each request if you frequently query for it

so which is more efficient and which is safer

for instance

IsAdmin should be a role/claim? but then if someone stole the cookie, nah nah, the cookie already contains userid/username/securitystamp, so even if it's a property, the userid on the stolen cookie would query on the custom identity user property, or is there something that will prevent this cookie from working when stolen ?

another instance

if i've 20 property for the user (first name, last name, address 1, address 2, postal code, whatever the case may be), should i simply have the user wait a bit for a bigger slower cookie to be send back and forth or should i do all the work from the db using custom identity user

but then, if i remove or add a claim to the user, would it be updated on the next request if it doesn't get queried or is the security stamp validate that this cookie is still valid ?

cause at the Task AddClaimsAsync of the userstore of efcore it only add the claim to the dbset

i apologize i know this is many questions to ask but the resources on the matter are not that good and one can easily get lost reading the identity source

2 Answers
Related