Update web pages

This commit is contained in:
Neo 2020-10-30 18:07:14 +00:00
parent 3bd276d217
commit e22c064a34
6 changed files with 63 additions and 5 deletions

View File

@ -0,0 +1,53 @@
using KamihamaWeb.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace KamihamaWeb.Controllers
{
public class ErrorController : Controller
{
[Route("Error/{statusCode}")]
[AllowAnonymous]
public IActionResult HttpStatusCodeHandler(int statusCode)
{
var feature = HttpContext.Features.Get<IStatusCodeReExecuteFeature>();
var path = feature?.OriginalPath;
if (!string.IsNullOrEmpty(path))
{
if (path.StartsWith("/api/v1"))
{
switch (statusCode)
{
case 404:
return new APIResult(404, "not found");
case 503:
return new APIResult(503, "service temporarily unavailable");
default:
return new APIResult(500, "an error has occurred");
}
}
}
switch (statusCode)
{
case 404:
ViewBag.Title = "404 Not Found";
ViewData["ErrorMessage"] = "The resource you requested could not be found.";
break;
case 503:
ViewBag.Title = "503 Service Unavailable";
ViewData["ErrorMessage"] = "The requested resource is currently unavailable.";
break;
default:
ViewBag.Title = "Unknown Error";
ViewData["ErrorMessage"] = "An unknown error occurred.";
break;
}
return View("HttpError");
}
}
}
}

View File

@ -71,6 +71,7 @@ namespace KamihamaWeb.Controllers
[Route("resource/{*url}")]
[HttpGet]
[HttpCacheExpiration(MaxAge = 60*60*24)]
public async Task<IActionResult> GetAsset(string url)
{
/*WebClient wc = new WebClient();

View File

@ -3,6 +3,6 @@
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
<h1 class="display-4">Kamihama API</h1>
<p>This isn't the page you're looking for.</p>
</div>

View File

@ -3,4 +3,4 @@
}
<h1>@ViewData["Title"]</h1>
<p>Use this page to detail your site's privacy policy.</p>
<p></p>

View File

@ -0,0 +1,4 @@
<div class="text-center">
<h1 class="display-4">Kamihama API Error</h1>
<p>@ViewData["ErrorMessage"]</p>
</div>

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - KamihamaWeb</title>
<title>@ViewData["Title"] - Kamihama</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" />
</head>
@ -11,7 +11,7 @@
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">KamihamaWeb</a>
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Kamihama</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>