Reputation: 499
Currently, I have such code at MainLayout.razor file. That is redirecting the request to any page to the Register page if a user is not logged. That is working quite well still I have two issues with that.
protected async override Task OnInitializedAsync()
{
base.OnInitialized();
var user = (await AuthStat).User;
if (!user.Identity.IsAuthenticated)
{
NavigationManager.NavigateTo($"Identity/Account/Register");
}
}
User is redirected to Identity/Account/Register even if he/she tries to access the page that has AllowAnonymous attribute.
That is not a problem, still, I'm curious why any request to a page other than Identity/Account/Register is redirected to Identity/Account/Register. All except Identity/Account/Login. That is how it should be still I don't know why that works that way.
Upvotes: 0
Views: 338
Reputation: 263
you can use like this
<AuthorizeRouteView RouteData="routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<RedirectToLogin></RedirectToLogin>
</NotAuthorized>
</AuthorizeRouteView>
full article is here.
Upvotes: 1