Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Rerouting to a specific page if the logged in user is not authorized to access the page

$
0
0

I am currently implementing the OAuth2.0 authentication and authorization with AzureAD in my Blazor application, and I'm facing some troubles.

For example, if the logged in user is not authenticated to access the 'Admin' page, it gets redirected to https://localhost:7155/MicrosoftIdentity/Account/AccessDenied?ReturnUrl=admin, and gives me 404 response. What I want it to happen is to get redirected to https://localhost:7155/AccessDenied instead.

I put the attribute

@attribute[Route("Admin")]@attribute [Authorize(Policy = "Admin")]

on top of the .razor page that I'm working on right now.

In Routes.razor, I also added the following:

<Found Context="routeData"><AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" ><NotAuthorized><AccessDenied /></NotAuthorized></AuthorizeRouteView><FocusOnNavigate RouteData="@routeData" Selector="h1" /></Found><NotFound><AccessDenied /></NotFound>

Any suggestion/idea would be appreciated.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>