Handling 404 Errors ASP.NET Core
In the file Startup.cs before the line app.UseHttpsRedirection(); in class Configure
app.UseStatusCodePagesWithReExecute("/error/{0}");
HomeController.cs
[Route("error/404")]
public IActionResult Error404()
{
return View();
}
Example Views/Home/Error404.cshtml
@{
ViewData["Title"] = "Page not found";
ViewData["BrowserTitle"] = "Page not found";
ViewData["Description"] = "Page not found";
}
<h1>Page not found</h1>
<div>
<table class="table table-striped">
<tr>
<td style="font-size: 24px; text-align: center"><a href="/">Go to the main page of the site</a></td>
</tr>
</table>
</div>