© 2026 Hedgehog Software, LLC

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

identity blazor

i have this code for getting user id of current user but its return null
csharp     protected override async Task OnParametersSetAsync()
    {
        var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
        var user = authState.User;

        if (string.IsNullOrEmpty(userId) && user.Identity.IsAuthenticated)
        {
            var userIdClaim = user.FindFirst(c => c.Type == "sub");
            userId = userIdClaim?.Value;
        }

        await LoadProfileData();
    }
csharp     protected override async Task OnParametersSetAsync()
    {
        var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
        var user = authState.User;

        if (string.IsNullOrEmpty(userId) && user.Identity.IsAuthenticated)
        {
            var userIdClaim = user.FindFirst(c => c.Type == "sub");
            userId = userIdClaim?.Value;
        }

        await LoadProfileData();
    }
i use blazor wasm and web api
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

Blazor - Identity Scaffolding Fails
C#CC# / help
2y ago
❔ Blazor and Auth - Identity
C#CC# / help
3y ago
❔ Blazor Server - scaffolding Identity error
C#CC# / help
3y ago
Blazor Wasm with Microsoft Identity Platform
C#CC# / help
2y ago