-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.razor
40 lines (35 loc) · 1.22 KB
/
App.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@inject NavigationManager NavigationManager
@inject AuthenticationStateProvider AuthenticationStateProvider
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
@{
HandleNotAuthorized();
}
</NotAuthorized>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Seite nicht gefunden.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
@code {
private async void HandleNotAuthorized()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (authState.User.Identity.IsAuthenticated)
{
NavigationManager.NavigateTo("/403");
}
else
{
var returnUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
NavigationManager.NavigateTo($"/401?returnUrl={Uri.EscapeDataString(returnUrl)}", true);
}
}
}