As per Sitecore's example code for ASP.NET Headless you can have your default controller method look like this:
[UseSitecoreRendering]
public IActionResult Index(Route route) {
var request = HttpContext.GetSitecoreRenderingContext();
if (request.Response.HasErrors) {
foreach (var error in request.Response.Errors) {
switch (error) {
case ItemNotFoundSitecoreLayoutServiceClientException notFound:
Response.StatusCode = (int)HttpStatusCode.NotFound;
return View("NotFound", request.Response.Content.Sitecore.Context);
case InvalidRequestSitecoreLayoutServiceClientException badRequest:
case CouldNotContactSitecoreLayoutServiceClientException transportError:
case InvalidResponseSitecoreLayoutServiceClientException serverError:
default:
throw error;
}
}
}
return View(route);
}
But I want to display a Sitecore page as the 404
page instead of a regular View inside the ASP.NET rendering host
.
Let's say I have a page at the following path in Sitecore: /sitecore/content/MySite/Home/ErrorPages/404
How would I go about rendering that specific page when the rendering host encounters a "NotFound" scenario? This has to work with model binding, of course.
I guess I have to do something instead of Return View("NotFound", request.Response.Content.Sitecore.Context);
but what?