Version-agnostic App component (#23699)
parent
b1779a9f51
commit
d46f3a2315
|
@ -7,32 +7,9 @@ The `App` component (`App.razor`) is similar to the `App` component found in Bla
|
|||
* The <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeRouteView> component makes sure that the current user is authorized to access a given page or otherwise renders the `RedirectToLogin` component.
|
||||
* The `RedirectToLogin` component manages redirecting unauthorized users to the login page.
|
||||
|
||||
```razor
|
||||
<CascadingAuthenticationState>
|
||||
<Router AppAssembly="@typeof(Program).Assembly">
|
||||
<Found Context="routeData">
|
||||
<AuthorizeRouteView RouteData="@routeData"
|
||||
DefaultLayout="@typeof(MainLayout)">
|
||||
<NotAuthorized>
|
||||
@if (!context.User.Identity.IsAuthenticated)
|
||||
{
|
||||
<RedirectToLogin />
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>
|
||||
You are not authorized to access
|
||||
this resource.
|
||||
</p>
|
||||
}
|
||||
</NotAuthorized>
|
||||
</AuthorizeRouteView>
|
||||
</Found>
|
||||
<NotFound>
|
||||
<LayoutView Layout="@typeof(MainLayout)">
|
||||
<p>Sorry, there's nothing at this address.</p>
|
||||
</LayoutView>
|
||||
</NotFound>
|
||||
</Router>
|
||||
</CascadingAuthenticationState>
|
||||
```
|
||||
Due to changes in the framework across releases of ASP.NET Core, Razor markup for the `App` component (`App.razor`) isn't shown in this section. To inspect the markup of the component for a given release, use ***either*** of the following approaches:
|
||||
|
||||
* Create an app provisioned for authentication from the default Blazor WebAssembly project template for the version of ASP.NET Core that you intend to use. Inspect the `App` component (`App.razor`) in the generated app.
|
||||
* Inspect the `App` component (`App.razor`) in [reference source](https://github.com/dotnet/aspnetcore/blob/main/src/ProjectTemplates/Web.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Client/App.razor).
|
||||
|
||||
[!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)]
|
||||
|
|
Loading…
Reference in New Issue