diff --git a/samples/AndreGoepel.AppFoundation.Sample/Components/Routes.razor b/samples/AndreGoepel.AppFoundation.Sample/Components/Routes.razor index 177dd40..97d6856 100644 --- a/samples/AndreGoepel.AppFoundation.Sample/Components/Routes.razor +++ b/samples/AndreGoepel.AppFoundation.Sample/Components/Routes.razor @@ -1,7 +1,10 @@ @using AndreGoepel.AppFoundation.Components.Layout +@using AndreGoepel.AppFoundation.Components.Pages @using AndreGoepel.Marten.Identity.Blazor.Components.Account.Shared - + diff --git a/src/AndreGoepel.AppFoundation.Hosting/Initialization.cs b/src/AndreGoepel.AppFoundation.Hosting/Initialization.cs index d95fb0f..d3a7a4f 100644 --- a/src/AndreGoepel.AppFoundation.Hosting/Initialization.cs +++ b/src/AndreGoepel.AppFoundation.Hosting/Initialization.cs @@ -232,6 +232,13 @@ public static WebApplication UseAppFoundation(this WebApplication app) app.UseExceptionHandler("/Error", createScopeForErrors: true); app.UseHsts(); } + + // Requests that match no endpoint at all (hard 404s) never reach the Blazor + // router, so re-execute them against the designed not-found page, passing the + // original status code so 403s render their own copy. Interactive navigations + // to unknown routes are handled by the Router's NotFoundPage. + app.UseStatusCodePagesWithReExecute("/not-found", "?code={0}"); + app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseHeaderPropagation(); diff --git a/src/AndreGoepel.AppFoundation/Components/Pages/Error.razor b/src/AndreGoepel.AppFoundation/Components/Pages/Error.razor index 576cc2d..f47017d 100644 --- a/src/AndreGoepel.AppFoundation/Components/Pages/Error.razor +++ b/src/AndreGoepel.AppFoundation/Components/Pages/Error.razor @@ -1,28 +1,40 @@ @page "/Error" @using System.Diagnostics -Error + -

Error.

-

An error occurred while processing your request.

+
+ -@if (ShowRequestId) -{ -

- Request ID: @RequestId -

-} +
+ Error + + An error occurred while processing your request. + +
+ + @if (ShowRequestId) + { + + Request ID: @RequestId + + } + + + + Development mode + + Swapping to the Development environment displays more detailed + information about the error. It shouldn't be enabled for deployed applications, as + it can leak sensitive information from exceptions to end users. For local debugging, + set the ASPNETCORE_ENVIRONMENT environment variable to + Development and restart the app. + + + -

Development Mode

-

- Swapping to Development environment will display more detailed information about the error that occurred. -

-

- The Development environment shouldn't be enabled for deployed applications. - It can result in displaying sensitive information from exceptions to end users. - For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development - and restarting the app. -

+
+
@code{ [CascadingParameter] diff --git a/src/AndreGoepel.AppFoundation/Components/Pages/NotFound.razor b/src/AndreGoepel.AppFoundation/Components/Pages/NotFound.razor index 6ff73e8..ec07cc4 100644 --- a/src/AndreGoepel.AppFoundation/Components/Pages/NotFound.razor +++ b/src/AndreGoepel.AppFoundation/Components/Pages/NotFound.razor @@ -1,3 +1,11 @@ +@page "/not-found" @rendermode InteractiveServer - + + +@code { + // Original status code when the status-code-pages middleware re-executes a bare + // 4xx response here (e.g. "?code=403"); absent for router-level not-found. + [SupplyParameterFromQuery(Name = "code")] + public string? Code { get; set; } +} diff --git a/src/AndreGoepel.AppFoundation/Components/Shared/ErrorPage.razor b/src/AndreGoepel.AppFoundation/Components/Shared/ErrorPage.razor index 4a820a7..b5f7128 100644 --- a/src/AndreGoepel.AppFoundation/Components/Shared/ErrorPage.razor +++ b/src/AndreGoepel.AppFoundation/Components/Shared/ErrorPage.razor @@ -1,6 +1,6 @@ @inject NavigationManager NavigationManager -@_copy.Title +