How do you restrict access to a specific Blazor component or page based on roles or policies?
Last updated
Protect routable pages with
@attribute [Authorize(Roles = "Admin")]orPolicy, enforced by wrapping the router inAuthorizeRouteView.Guard parts of markup with
<AuthorizeView Roles="...">and define custom policies viaAddAuthorizationCoreandAddPolicy.These only guard the UI, so also apply server-side
[Authorize]on the APIs.
- https://learn.microsoft.com/en-us/aspnet/core/blazor/security/?view=aspnetcore-10.0
- https://learn.microsoft.com/en-us/aspnet/core/security/authorization/roles?view=aspnetcore-10.0
- https://learn.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-10.0
- https://auth0.com/blog/role-based-access-control-in-blazor-apps/
- https://www.telerik.com/faqs/blazor/blazor-authorizeview
- https://amarozka.dev/blazor-authorization-authentication/