public class RedirectionPageController : RenderMvcController
{
public ActionResult Index(RenderModel model)
{
var child = model.Content.FirstChild();
var viewName = child.GetTemplateAlias();
if(viewName.IsNullOrWhiteSpace())
{
return new HttpStatusCodeResult(HttpStatusCode.NotFound);
}
return View(viewName, child);
}
}
I want to render view of first child of that page, but if it have no template - render the 404 page. But builtin Umbraco 404-handling behavior does't executed in case. All the others pages (without hijacking) without views (templates) working well with builtin 404-handling.
Route Hijacking with builtin 404 handling
Hello, Umbracians
Here is my code:
I want to render view of first child of that page, but if it have no template - render the 404 page. But builtin Umbraco 404-handling behavior does't executed in case. All the others pages (without hijacking) without views (templates) working well with builtin 404-handling.
How to make Umbraco force it own 404 handling?
I think you need to use the IContentFinder instead if you want the default 404-handling to be in effect.
https://our.umbraco.com/documentation/reference/routing/request-pipeline/icontentfinder
I made a quick example for you tested with Umbraco 8:
For Umbraco 7 you should replace IUserComposer with IApplicationEventHandler and put the code in ApplicationStarting
Hi, Dennis
A good solution, but not what I need.
I don't want to make my own ContentFinder, I need to use the builtin implementation of it.
Are there any other approaches for?
I think I have to get ContentFinder collection and find LastChanceContentFinder or something like that.
Thanks
is working on a reply...