Custom error pages in ASP.NET MVC Core
app.Use(async (ctx, next) => { await next(); if(ctx.Response.StatusCode == 404 && !ctx.Response.HasStarted) { //Re-execute the request so the user gets the error page string originalPath = ctx.Request.Path.Value; ctx.Items["originalPath"] = originalPath; ctx.Request.Path = "/error/404"; await next(); } });