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

Blazor isn't using my component for redirecting unauthorized users

$
0
0

I'm trying to implement authorization in a .NET 8 Blazor server-side app. When a user isn't logged in and tries to access a page that requires authorization, I want to redirect to the login page. I did the same thing the default Blazor Web App template with "Individual Accounts" does but used a different URI. But my URI is ignored and the redirect goes to /Account/Login. Am I misinterpreting what <NotAuthorized> does?

Here's Routes.razor:

@using DataCollection.UI.Components.Shared<Router AppAssembly="typeof(Program).Assembly"><Found Context="routeData"><AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)"><NotAuthorized><RedirectToLogin /></NotAuthorized></AuthorizeRouteView><FocusOnNavigate RouteData="routeData" Selector="h1" /></Found></Router>

Here's RedirectToLogin.razor (defined in DataCollection.UI.Components.Shared):

@inject NavigationManager NavigationManager@attribute [AllowAnonymous]@code {    protected override void OnInitialized()    {        NavigationManager.NavigateTo($"ui/Login?returnUrl={Uri.EscapeDataString(NavigationManager.Uri)}", forceLoad: true);    }}

Viewing all articles
Browse latest Browse all 4839

Trending Articles



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