I want to display different error messages for each status code e.g:
Works with various status codes without specifying each one individually in the controller.
Startup.cs:
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
app.UseStatusCodePagesWithRedirects("/StatusCodes?statusCode={0}");
app.UseMvcWithDefaultRoute();
Controller:
public class StatusCodesController : Controller
{
public IActionResult Index(string statusCode)
{
if(statusCode == null) statusCode = "";
if(statusCode == "404") return View("Error404");
return View("Index",statusCode);
}
public IActionResult Test404() { return StatusCode(404); }
public IActionResult Test500() { return StatusCode(500); }
View:
@model string
@{ ViewData["Title"] = Model + " Oops!"; }