I want to return 404 from a RenderController if certain criteria is met (or rather not met :))
I’ve come up with this code, that gets an IPublishedRequestBuilder, which then can be fed into the IContentLastChanceFinder to find the current 404 page, and then return that.
var request = await publishedRouter.CreateRequestAsync(umbracoContext.CleanedUmbracoUrl);
if (await contentLastChanceFinder.TryFindContent(request) && request.PublishedContent?.GetTemplateAlias() is {} view)
{
HttpContext.Response.StatusCode = 404;
return View(view, request.PublishedContent);
}
But this bypasses route hijacking for the 404 page. For now it’s probably not a problem, I’m just curious if there is a better way?
If I just return NotFound() it just gives an empty 404 page, instead of the one configured in Umbraco.