My aurhorization shows fore alittle my mainlayout and then redirect to unauthorizedpage

Ioannis Karakostas 0 Reputation points
2024-06-11T08:22:45.62+00:00
<Router AppAssembly="@typeof(Admin).Assembly">
	<Found Context="routeData">
		<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainAdminLayout)">
			<NotAuthorized>
				@{
					_navigationManager.NavigateTo("Unauthorized", true);
				}
			</NotAuthorized>
			<Authorizing>
				Loading..
			</Authorizing>
		</AuthorizeRouteView>
	</Found>
	<NotFound>
		<PageTitle>Not found</PageTitle>
		<LayoutView>
			<p role="alert">Sorry, there's nothing at this address</p>
		</LayoutView>
	</NotFound>
</Router>

When i open the app it shows my mainlayout for a little and the goes to unauthorizedpage. Is there a way to prevent this??
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,618 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,595 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 66,866 Reputation points
    2024-06-13T22:30:10.0433333+00:00

    most likely you are using server pre-render. the pre-render render displays the app as static html. the html includes the Blazor bootstrap code, which loads the interactive instance of Blazor. Once the interactive instance loads and starts, it executes the navigate request.

    you have a couple options:

    • make the <NotAuthorized> a splash screen
    • if using Blazor server or cookie authenication, you can use middleware to force authentication before the static render
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.