C
C#8mo ago
Iron

❔ Avoid "Authorizing..." in Blazor Page (Identity)

I am trying to avoid the loading text "Authorizing..." when going to my index.razor page. I have added
`@attribute [AllowAnonymous]
`@attribute [AllowAnonymous]
` to the top of the page but does not seem to solve it. I am able to change the text of the "Authorizing..." in the CascadingAuthenticationView in app.razor but i need to get rid of it on some of my pages because sometimes it takes time to load. Any tips?
6 Replies
Iron
Iron8mo ago
App.razor:
`<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
@if (context.User.Identity?.IsAuthenticated != true)
{
<RedirectToLogin />
}
else
{
<p role="alert">Du saknar behörighet.</p>
}
</NotAuthorized><Authorizing>
<p>Laddar....</p>
</Authorizing>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Tyvärr, vi hittade inget på denna adress...</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
`<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
@if (context.User.Identity?.IsAuthenticated != true)
{
<RedirectToLogin />
}
else
{
<p role="alert">Du saknar behörighet.</p>
}
</NotAuthorized><Authorizing>
<p>Laddar....</p>
</Authorizing>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Tyvärr, vi hittade inget på denna adress...</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
`
Anu6is
Anu6is8mo ago
You don't have to wrap the entire app in cascading auth, you can wrap the main layout in it and use a separate layout for your index page
Iron
Iron8mo ago
This app.razor is from the template i started the project with. Could you give me an example or a link ? Thanks for your answer thats good to know, im just unsure what to do should i remove cascading from app.razor and wrap it around pages that i need it on or ?
Anu6is
Anu6is8mo ago
create a new layout component and have your index page use that layout @layout YourLayout
Iron
Iron8mo ago
Thank you so much.
Accord
Accord8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.