© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
2 replies
BakaPresident

❔ Getting Identity from [Authorize]

Hey there, since i'm using [Authorize] i thought i should be able to get UserID from
var userId = HttpContext.User.FindFirstValue("nameid");

But userId keeps returning null.
For context, this is how i build the claims in my AuthService
        var claims = new List<Claim>
        {
            new Claim(JwtRegisteredClaimNames.Sub, user.Email),
            new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
            new Claim(JwtRegisteredClaimNames.Email, user.Email),
            new Claim(JwtRegisteredClaimNames.NameId, user.Id)
        }.Union(roleClaims).Union(userClaims);
        var claims = new List<Claim>
        {
            new Claim(JwtRegisteredClaimNames.Sub, user.Email),
            new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
            new Claim(JwtRegisteredClaimNames.Email, user.Email),
            new Claim(JwtRegisteredClaimNames.NameId, user.Id)
        }.Union(roleClaims).Union(userClaims);
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

Why is my JWT token not getting authorized and not getting entering the [Authorize] method?
C#CC# / help
16mo ago
Moving Endpoints (from Identity) to another Controller
C#CC# / help
2y ago
✅ Identity Help
C#CC# / help
13mo ago
identity blazor
C#CC# / help
2y ago