Custom 404 and 500 pages via ErrorController.cs

I followed the doc on implementing custom error pages, and I can only get the 404 page to work via the appsettings.json “Error404Collection” setting, but not a 404 and 500 error message via the suggested controller implementation. I can debug and see it go to my nodes at /error/404 and /error/500, but it doesn’t display the content page created for them, but instead shows the default browser error.

This is what I have for the controller (which does work when stepping through):


using Microsoft.AspNetCore.Mvc;

namespace USD.Site.Controllers;
public class ErrorController : Controller
{
[Route(“Error”)]
public IActionResult Index()
{
if(Response.StatusCode == StatusCodes.Status500InternalServerError)
{
return Redirect(“/error/500”);
}
else if(Response.StatusCode != StatusCodes.Status200OK)
{
return Redirect(“/error/404”);
}
return Redirect(“/”);
}
}

For now I’ll use the appSettings.json setting and just always use the 404 content node, but I wanted to setup the 500 to display if applicable too.

This is my working error controller (NOT 404, that uses the umbraco 404)

    public class ErrorController : Controller
    {
        [Route("Error")]
        public IActionResult Index()
        {
            if (Response.StatusCode == StatusCodes.Status500InternalServerError)
            {
                return Redirect("/statuscodes/500");
            }
            else if (Response.StatusCode != StatusCodes.Status200OK)
            {
                return Redirect("/statuscodes");
            }
            return Redirect("/");
        }


    }

In my Umbraco site I have these defined

Those snippets should work so long as you have all the other pieces in place as per the Custom 500 Tutorial in the documentation :thinking: Did you check that the appsettings CMS:Global:ReservedPaths has your ~/error/ path added? And the program.cs modified to let yah test it?