See: Redirect to 404.html doesnt work on second time
We found that in case of a 404 error, DXA wants to open a custom page "error-404.html" in the Home Structure Group, like in the example website. However, we want to change the location of that page to a sub Structure Group folder (any maybe the name as well) but we cannot find where that setting is set. Can anyone tell us where that is set?
14-4-2021 Additional info after suggested solution of Atila Sos. This is the code that I created for the override of the NotFound method but somehow it is not hit when a non existing page is requested in the browser. What do I do wrong?
using System.Web;
using System.Web.Mvc;
using Sdl.Web.Common;
using Sdl.Web.Common.Logging;
using Sdl.Web.Common.Models;
using Sdl.Web.Mvc.Configuration;
using Sdl.Web.Mvc.Formats;
namespace Sdl.Web.Mvc.Controllers
{
public class CustomPageController : PageController
{
/// <summary>
/// Render a custom file not found page
/// </summary>
/// <returns>404 page or HttpException if there is none</returns>
[FormatData]
public override ActionResult NotFound()
{
using (new Tracer())
{
string notFoundPageUrl = WebRequestContext.Localization.Path + "/Subfolder/Errors" + "/404";
PageModel pageModel;
try
{
pageModel = ContentProvider.GetPageModel(notFoundPageUrl, WebRequestContext.Localization);
}
catch (DxaItemNotFoundException ex)
{
Log.Error(ex);
throw new HttpException(404, ex.Message);
}
SetupViewData(pageModel);
PageModel model = EnrichModel(pageModel) as PageModel ?? pageModel;
WebRequestContext.PageModel = model;
Response.StatusCode = 404;
return View(model.MvcData.ViewName, model);
}
}
}
}