❔ .Net Core API User.FindFirstValue(ClaimTypes.NameIdentifier) in every action?!
Hi everyone I have the end point below
now the line where i get the userId is being repeated in every action where i need the userId. is there a better way to have this value saved globally or in the controller scope or something?
6 Replies
I just created an extension method so I can do
var uid = User.GetNumericId()
and donethats smart
But you could probably create your own controller class that inherits
Controller
or ControllerBase
or whatever you need, and adds user ID as a property or a field
Then have all your controllers inherit thati think ill do that as well
i tried doing that but it didnt work
what does ur extension method return if userId not found
null?
It's nullable
So I can easily do
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.