I'm trying to use custom middeware to handle 404 error:
app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404)
{
context.Request.Path = "/error/404";
await next();
}
});
But the needed action is not called in Error Controller:
[Route("error")]
public class ErrorController : Controller
{
public ErrorController()
{
}
[Route("404")]
public IActionResult PageNotFound()
{
return View();
}
}
I've checked that it's getting called if to make a call directly like "http:\localhost\error\404"