© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
12 replies
AAA

❔ .Net Core API User.FindFirstValue(ClaimTypes.NameIdentifier) in every action?!

Hi everyone I have the end point below
[HttpPost, Route("stores/new"), Authorize(policy: "client")]
        public async Task<IActionResult> AddNewStore(NewStoreRequestDto store)
        {
            int userId = int.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier));
//do something
        }
[HttpPost, Route("stores/new"), Authorize(policy: "client")]
        public async Task<IActionResult> AddNewStore(NewStoreRequestDto store)
        {
            int userId = int.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier));
//do something
        }

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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ ClaimTypes.NameIdentifier not retruning id of current user
C#CC# / help
2y ago
✅ Testing in ASP.NET Core Web Api
C#CC# / help
9mo ago
API integration issue in .NET core framework.
C#CC# / help
2y ago
✅ ASP.Net Core Web API
C#CC# / help
6mo ago