简体   繁体   中英

Storing logged user on asp net core 2

I need suggestion about storing logged user. i have front application and we are using token for authorization, I check that token on some authentication server, then I got user from db to do some extra checks for access rights.. But somewhere I need that user again (like to log some changes that he did), and I need advice, is it better to every time get user's email from token, then need to ping database or it's better to make same global variable and to get it when I need.. I know that second approach is faster, but is it good one?

When you authorise a user using token, the best way is to add this to the ClaimsPrinciple (claims). Then you can be able to access it using Identity.User

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM