Hi @Mahdi Elahi,
Here is a whole working demo:
Register.razor
user.Fullname = "Full_"+user.UserName; //set the fullname, just for easy testing
var result = await UserManager.CreateAsync(user, Input.Password);
if (!result.Succeeded)
{
identityErrors = result.Errors;
return;
}
//add the Fullname claims
await UserManager.AddClaimAsync(user, new System.Security.Claims.Claim("Fullname", user.Fullname));
Show full name in component:
@page "/auth"
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]
@inject AuthenticationStateProvider authenticationStateProvider
<AuthorizeView>
<Authorized>
<p>Hello @fullname</p>
</Authorized>
</AuthorizeView>
@code {
private string fullname;
protected override async Task OnInitializedAsync()
{
var authState = await authenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;
// Get the Fullname claim
var fullnameClaim = user.FindFirst("Fullname");
if (fullnameClaim != null)
{
fullname = fullnameClaim.Value;
}
}
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Rena