How To Get Current User in a Blazor component

Let’s assume you have configured Blazor authentication and authorization in your project, and you want to access the username/claim in your view. Then, you can wrap the component into AuthorizeView and access the User details from the @context property.

@context property will be not available if the component is not inside the AuthorizeView

<AuthorizeView>
    Hello, @context.User.Identity.Name!
</AuthorizeView>

Please do not post any spam link in the comment box😊

Post a Comment (0)
Previous Post Next Post