I have created a Blazor Server project in .NET 6. I want to implement my own custom authentication in this project. So I have created a login component under Page/Account folder. In that account folder there is a new Layout page. And I have configured my App.razor file below so that while not authenticated it redirects to the login page.
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeView>
<Authorized>
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Authorized>
<NotAuthorized>
<LoginRedirect></LoginRedirect>
</NotAuthorized>
</AuthorizeView>
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<AuthorizeView>
<Authorized>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</Authorized>
<NotAuthorized>
<LoginRedirect></LoginRedirect>
</NotAuthorized>
</AuthorizeView>
</NotFound>
</Router>
</CascadingAuthenticationState>
Here is my LoginRedirect component code:
public partial class LoginRedirect
{
[Inject] NavigationManager? NavigationManager { get; set; }
protected override async Task OnInitializedAsync()
{
var returnUrl = NavigationManager?.ToBaseRelativePath(NavigationManager.Uri);
NavigationManager?.NavigateTo($"/account/login/{returnUrl}", false);
await base.OnInitializedAsync();
}
}
When I am running the project I get the below error:
I have uploaded the project in github. Here is the github link . Can anyone help me to solve the problem?