.NET 8 Blazor @attribute [Authorize(Roles = "Admin")] not working #56773
Labels
area-blazor
Includes: Blazor, Razor Components
✔️ Resolution: Duplicate
Resolved as a duplicate of another issue
Status: Resolved
Is there an existing issue for this?
Describe the bug
I am trying to use roles via the authorise attribute
@attribute [Authorize(Roles = "Admin")]
to limit access to razor pages but this doesn't seem to be working as expected and despite the Claims containing the matching role I'm getting a 401 unauthorised page.Oddly if I use
<AuthorizeView Roles="Admin">
this works and seems to respect the roles in the claims as I would expect. I have also created a page that lists out the claims and the role 'Admin' is listed out so as far as I can see the role is correct.I am using a custom AuthenticationStateProvider as the end goal is to have the roles coming from an API for my use case but for this example I have just hard coded values to isolate the cause of my error.
`using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components.Authorization;
public class CustomAuthStateProvider : AuthenticationStateProvider
{
public override Task GetAuthenticationStateAsync()
{
}`
Expected Behavior
Steps To Reproduce
Exceptions (if any)
No response
.NET Version
8.0.303
Anything else?
No response
The text was updated successfully, but these errors were encountered: