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>

Post a Comment

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

Previous Post Next Post

Blog ads

CodeGuru