# My Blazor Server app won't display the user name

**URL:** <https://community.auth0.com/t/my-blazor-server-app-wont-display-the-user-name/85054>\
**Category:** Get Help\
**Tags:** username, server, blazor, auth0\
**Created:** [June 14, 2022, 12:42am UTC](https://community.auth0.com/t/my-blazor-server-app-wont-display-the-user-name/85054 "2022-06-14T00:42:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnMarsing](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/johnmarsing/32/8280_2.png) [@JohnMarsing](https://community.auth0.com/u/JohnMarsing)\
**Post date:** [June 14, 2022, 12:42am UTC](https://community.auth0.com/t/my-blazor-server-app-wont-display-the-user-name/85054/1 "2022-06-14T00:42:53Z")

</div>

I can’t get my Shared\LoginDisplay.razor to display the user name.

This should work…

```plaintext
<AuthorizeView>
	<Authorized>
			Hello @context.User.Identity.Name
	</Authorized>
	<NotAuthorized>
		<a href="@Login" class="btn btn-xs btn-outline-info float-right text-black-50">
			<u>Log in</u> <i class="fas fa-sign-in-alt"></i>
		</a>
	</NotAuthorized>
</AuthorizeView>
	

```

I have followed this [blog](https://andrewlock.net/adding-authentication-to-a-blazor-server-app-using-auth0/) but to no avail.

The app uses net6.0 framework

When I list my claims, one of the items is…  
`http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name`  
with the proper value of the user name, but I should get it with `@context.User.Identity.Name`

hope this makes sense  
thanks, john

---

<div class="post-metadata">

**Author:** ![cellaret](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cellaret/32/46799_2.png) [@cellaret](https://community.auth0.com/u/cellaret)\
**Post date:** [April 30, 2023, 11:45pm UTC](https://community.auth0.com/t/my-blazor-server-app-wont-display-the-user-name/85054/2 "2023-04-30T23:45:42Z")

</div>

I read in one of the more recent blog posts on setting up your Blazor app that using “context” was frowned upon. I don’t know why - I’m a bit of a Blazor newb myself (not to MVC, mind you, just Blazor). But regardless, the article mentioned that you should be DI (direct injecting) access to the AuthencationState and then pulling it from there. For example, in your razor page or component:

@inject AuthencationState state;

…

```auto
@code {
    private string imageUrl = "";
    private string nameAndEmail = "";

    protected override async Task OnInitializedAsync()
    {
        var state = await authState.GetAuthenticationStateAsync();
        var email = Auth0Util.GetEmail(state?.User);
        var name = Auth0Util.GetName(state?.User);
        nameAndEmail = $"{name} ({email})";
        imageUrl = Auth0Util.GetImageUrl(state?.User);

        await base.OnInitializedAsync();
    }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [November 18, 2024, 10:41pm UTC](https://community.auth0.com/t/my-blazor-server-app-wont-display-the-user-name/85054/3 "2024-11-18T22:41:29Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
