Rework page errors (again)

This commit is contained in:
Laura Hausmann 2022-11-26 14:04:19 +01:00
parent 4ea6a19cf6
commit 09587b0dba
Signed by: zotan
GPG key ID: D044E84C5BE01605
4 changed files with 21 additions and 11 deletions

View file

@ -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();

View file

@ -1,11 +1,24 @@
@page
@using Microsoft.AspNetCore.WebUtilities
@model ErrorModel
@{
ViewData["Title"] = "error";
ViewData["Title"] = $"error_{Response.StatusCode}";
}
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
@if (Response.StatusCode == 200) {
<h1>No error occured.</h1>
<p>Why are you here?</p>
}
else {
<h1>Error @Response.StatusCode: @ReasonPhrases.GetReasonPhrase(Response.StatusCode)</h1>
if (Response.StatusCode == 404) {
<p>The page you requested does not exist on this server.</p>
}
else {
<p>An error occurred while processing your request.</p>
}
}
@if (Model.ShowRequestId) {
<p>

View file

@ -1,7 +0,0 @@
@page
@{
ViewData["Title"] = "error_404";
}
<h1 class="text-danger">Not found.</h1>
<p>The page you requested does not exist on this server.</p>

View file

@ -26,6 +26,10 @@
<None Remove="database.db"/>
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="Pages\ErrorPages\404.cshtml"/>
</ItemGroup>
<Target Name="SetSourceRevisionId" BeforeTargets="InitializeSourceControlInformation">
<Exec Command="git describe --long --always --dirty --exclude=* --abbrev=8" ConsoleToMSBuild="True" IgnoreExitCode="False">
<Output PropertyName="SourceRevisionId" TaskParameter="ConsoleOutput"/>