From f87bac4266b1895219190a1cb2a52ca8f2166476 Mon Sep 17 00:00:00 2001 From: Michael Gordeev Date: Mon, 30 Mar 2020 19:23:07 +0300 Subject: [PATCH] Updated error page Updated web.config Updated README.md --- .../MyWebsite/Controllers/HomeController.cs | 9 ++++++--- MyWebsite/MyWebsite/Startup.cs | 1 + MyWebsite/MyWebsite/ViewModels/ErrorViewModel.cs | 12 ------------ MyWebsite/MyWebsite/Views/Shared/Error.cshtml | 16 ++++++---------- MyWebsite/MyWebsite/web.config | 10 +++++----- README.md | 4 ++-- 6 files changed, 20 insertions(+), 32 deletions(-) delete mode 100644 MyWebsite/MyWebsite/ViewModels/ErrorViewModel.cs diff --git a/MyWebsite/MyWebsite/Controllers/HomeController.cs b/MyWebsite/MyWebsite/Controllers/HomeController.cs index eefde7a..01ff29d 100644 --- a/MyWebsite/MyWebsite/Controllers/HomeController.cs +++ b/MyWebsite/MyWebsite/Controllers/HomeController.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using MyWebsite.Models.Databases; using MyWebsite.ViewModels; @@ -28,6 +27,10 @@ namespace MyWebsite.Controllers [Route("Error")] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() => - View(new ErrorViewModel(Database) { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + View(); + + [Route("GetError")] + public IActionResult GetError(int errorCode = 404) => + StatusCode(errorCode); } } \ No newline at end of file diff --git a/MyWebsite/MyWebsite/Startup.cs b/MyWebsite/MyWebsite/Startup.cs index 32ab11a..c3d913c 100644 --- a/MyWebsite/MyWebsite/Startup.cs +++ b/MyWebsite/MyWebsite/Startup.cs @@ -54,6 +54,7 @@ namespace MyWebsite app.UseHsts(); } app.UseHttpsRedirection(); + app.UseStatusCodePagesWithReExecute("/Error"); app.UseStaticFiles(); app.UseRouting(); diff --git a/MyWebsite/MyWebsite/ViewModels/ErrorViewModel.cs b/MyWebsite/MyWebsite/ViewModels/ErrorViewModel.cs deleted file mode 100644 index 182ebf1..0000000 --- a/MyWebsite/MyWebsite/ViewModels/ErrorViewModel.cs +++ /dev/null @@ -1,12 +0,0 @@ -using MyWebsite.Models.Databases; - -namespace MyWebsite.ViewModels -{ - public class ErrorViewModel : ViewModelBase - { - public ErrorViewModel(DatabaseContext context) : base(context) { } - - public string RequestId { get; set; } - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); - } -} \ No newline at end of file diff --git a/MyWebsite/MyWebsite/Views/Shared/Error.cshtml b/MyWebsite/MyWebsite/Views/Shared/Error.cshtml index f2414f8..5f2666e 100644 --- a/MyWebsite/MyWebsite/Views/Shared/Error.cshtml +++ b/MyWebsite/MyWebsite/Views/Shared/Error.cshtml @@ -1,19 +1,15 @@ -@model ErrorViewModel +@using Microsoft.AspNetCore.WebUtilities @{ ViewData["Title"] = "Error"; } -
-

Error

-

An error occurred while processing your request.

+

Error @Context.Response.StatusCode

+

@ReasonPhrases.GetReasonPhrase(Context.Response.StatusCode)

- @if (Model.ShowRequestId) - { -

- Request ID: @Model.RequestId -

- } +

+ +

\ No newline at end of file diff --git a/MyWebsite/MyWebsite/web.config b/MyWebsite/MyWebsite/web.config index c6e201a..26020b0 100644 --- a/MyWebsite/MyWebsite/web.config +++ b/MyWebsite/MyWebsite/web.config @@ -7,25 +7,25 @@ - + - + - + - + - + diff --git a/README.md b/README.md index ca2fac9..71ca8f8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # XFox111.NET -![Website](https://img.shields.io/website?down_message=offline&label=XFox111.NET&up_message=online&url=https%3A%2F%2Fxfox111.net%2FSiteInfo) +[![Website](https://img.shields.io/website?down_color=red&down_message=offline&label=XFox111.NET&up_color=green&up_message=online&url=https%3A%2F%2Fxfox111.net)](https://xfox111.net) [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) ![GitHub repo size](https://img.shields.io/github/repo-size/xfox111/CVWebsite?label=Repository%20size) @@ -23,4 +23,4 @@ Check out my website on https://xfox111.net/ At the moment this repository **is not intended** to be used as a basement for other personal websites and used to represent my ASP.NET skills. I'll fix this issue later ## Copyrights -> ©2019 Michael "XFox" Gordeev +> ©2020 Michael "XFox" Gordeev \ No newline at end of file