A free and open-source web framework that enables developers to create web apps using C# and HTML, developed by Microsoft.
Here is a Blazor example from the official documentation for retrieving the name of the user's first role:
<AuthorizeView>
<Authorized>
<p>@context.User.Claims.FirstOrDefault(c=>c.Type == "role").Value</p>
</Authorized>
</AuthorizeView>
The best way to retrieve the role is to get it from the roles claim in the JWT token (http://schemas.microsoft.com/ws/2008/06/identity/claims/role ).
In your authorization code, it is recommended to check whether a particular claim value is present, rather than assuming the user has just one role claim.
if (context.User.HasClaim(ClaimTypes.Role, "Admin")) { ... }
See related threads:
Let me know if this is close to what you are looking for. We don't have an exact sample for this.
If the information helped you, please Accept the answer. This will help us as well as others in the community who may be researching similar questions. Otherwise let us know if you have further questions.