79216615

Date: 2024-11-22 21:31:20
Score: 0.5
Natty:
Report link

In my Program.cs file I added:

builder.Services.Configure<CookieAuthenticationOptions>(CookieAuthenticationDefaults.AuthenticationScheme, options =>
{
    options.AccessDeniedPath = "/access-denied";
});

I added my custom AccessDenied.razor component/page and using

@attribute [Authorize(Roles = "Admin,Standard")]

at the top of pages or the AuthorizeView tag in the pages

<CascadingAuthenticationState>
                <AuthorizeView Policy="RequireValidUser" Context="ImpersonationComponent">
                    <Authorized>
                        <Login />
                    </Authorized>
                </AuthorizeView>
            </CascadingAuthenticationState>

I was able to get role based authorization working.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: esr124