Answer the question
In order to leave comments, you need to log in
A few questions about blazor server side?
Good day.
I started to study blazor (SERVER SIDE (!)) and faced with not understanding and inability to find answers to my questions in Google.
1. How to make it so that when entering the site, it immediately redirects to the authorization page, i.e. all pages of the site were available only to an authorized user;
2. Can pages be transferred to libraries? I tried to transfer the authorization page to a separate library in the Pages folder, but the application stubbornly does not see this page. It only prints "Sorry, there's nothing at this address.";
Perhaps I have a partial answer to the first question from Google, but I'm not sure if it's correct, I'm attaching:
Added an authorization attribute to _Imports.razor:
@attribute [Authorize]
In App.razor I changed the structure to:
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<RedirectToLogin/>
</NotAuthorized>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
@inject NavigationManager navManager
@code {
protected override void OnInitialized()
{
navManager.NavigateTo("login");
}
}
@page "/login"
<h1>LOGIN PAGE</h1>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question