Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Didier Marin 14 posts 86 karma points
    16 days ago
    Didier Marin

    SetContentLastChanceFinder and Custom route

    hello I have a problem with SetContentLastChanceFinder.

    I've defined a custom route (via MapControllerRoute) that calls a controller to render a view for content that does not exist as an umbraco node.

    The problem is that Umbraco triggers first the SetContentLastChanceFinder and assigns the published content to my 404 page, and after that goes to the routing and the correct controller. In that controller, CurrentPage has the correct value, but in the view, the Umbraco.AssignedContentItem is my 404 page

    The SetContentLastChanceFinder is configured like this

        public static IUmbracoBuilder AddNotFoundFinder(this IUmbracoBuilder builder)
        return builder;

    The routing is defined like this

        public static IUmbracoEndpointBuilderContext UseMyEndpoints(this IUmbracoEndpointBuilderContext app)
                new { Controller = "DetailPage", Action = "HtmlDetail" })
        return app;
    private static IPublishedContent FindContent(ActionExecutingContext actionExecutingContext)
        var myService = actionExecutingContext.HttpContext.RequestServices.GetRequiredService<IMyService>();
        var dpSearchPage = myService.GetSearchPage();
        return dpSearchPage;

    In the startup, I have this

            .WithMiddleware(u =>
                if (includeBackoffice)
            .WithEndpoints(u =>
                if (includeBackoffice)
                //This part only if we need to minify javascript in the frontend,
                //if just APIs we can remove this part

    How can I be sure that the Umbraco.AssignedContentItem is correctly set ? And why the SetContentLastChanceFinder is called before the routing ?

    When I enter a URL that doesn't exist I have the correct 404 return code, but with the routing, even if it goes first on the SetContentLastChanceFinder and if the Umbraco.AssignedContentItem is the cutom 404 page, the return code is 200

Please Sign in or register to post replies

Write your reply to: