From 09587b0dbad70edde66e2900dec5097524eed246 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sat, 26 Nov 2022 14:04:19 +0100 Subject: [PATCH] Rework page errors (again) --- Backend/Startup.cs | 2 +- Pages/Error.cshtml | 19 ++++++++++++++++--- Pages/ErrorPages/404.cshtml | 7 ------- zotan.pw-web.csproj | 4 ++++ 4 files changed, 21 insertions(+), 11 deletions(-) delete mode 100644 Pages/ErrorPages/404.cshtml diff --git a/Backend/Startup.cs b/Backend/Startup.cs index 663e4a8..a6d4c5e 100644 --- a/Backend/Startup.cs +++ b/Backend/Startup.cs @@ -32,7 +32,7 @@ if (!app.Environment.IsDevelopment()) { var provider = new FileExtensionContentTypeProvider { Mappings = { [".gpg"] = "application/pgp-signature" } }; app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = provider }); -app.UseStatusCodePagesWithReExecute("/ErrorPages/{0}"); +app.UseStatusCodePagesWithReExecute("/error"); app.UseSession(); app.UseRouting(); diff --git a/Pages/Error.cshtml b/Pages/Error.cshtml index 5e0abe5..f9e3a88 100644 --- a/Pages/Error.cshtml +++ b/Pages/Error.cshtml @@ -1,11 +1,24 @@ @page +@using Microsoft.AspNetCore.WebUtilities @model ErrorModel @{ - ViewData["Title"] = "error"; + ViewData["Title"] = $"error_{Response.StatusCode}"; } -

Error.

-

An error occurred while processing your request.

+@if (Response.StatusCode == 200) { +

No error occured.

+

Why are you here?

+} + +else { +

Error @Response.StatusCode: @ReasonPhrases.GetReasonPhrase(Response.StatusCode)

+ if (Response.StatusCode == 404) { +

The page you requested does not exist on this server.

+ } + else { +

An error occurred while processing your request.

+ } +} @if (Model.ShowRequestId) {

diff --git a/Pages/ErrorPages/404.cshtml b/Pages/ErrorPages/404.cshtml deleted file mode 100644 index 1e2079f..0000000 --- a/Pages/ErrorPages/404.cshtml +++ /dev/null @@ -1,7 +0,0 @@ -@page -@{ - ViewData["Title"] = "error_404"; -} - -

Not found.

-

The page you requested does not exist on this server.

diff --git a/zotan.pw-web.csproj b/zotan.pw-web.csproj index e38af5f..4c2ec9c 100644 --- a/zotan.pw-web.csproj +++ b/zotan.pw-web.csproj @@ -26,6 +26,10 @@ + + <_ContentIncludedByDefault Remove="Pages\ErrorPages\404.cshtml"/> + +