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 15 posts 87 karma points
    Sep 13, 2023 @ 12:10
    Didier Marin
    0

    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)
    {
        builder.SetContentLastChanceFinder<NotFoundContentFinder>();
    
        return builder;
    }
    

    The routing is defined like this

        public static IUmbracoEndpointBuilderContext UseMyEndpoints(this IUmbracoEndpointBuilderContext app)
    {
        app.EndpointRouteBuilder.MapControllerRoute(
                "HtmlDetails",
                "{language}/search/details/{id}",
                new { Controller = "DetailPage", Action = "HtmlDetail" })
                .ForUmbracoPage(FindContent);
    
        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

     app.UseUmbraco()
            .WithMiddleware(u =>
            {
                if (includeBackoffice)
                {
                    u.UseBackOffice();
                }
                u.UseWebsite();
            })
            .WithEndpoints(u =>
            {
                u.UseMyEndpoints();
    
                if (includeBackoffice)
                {
                    u.UseInstallerEndpoints();
                    u.UseBackOfficeEndpoints();
                }
                //This part only if we need to minify javascript in the frontend,
                //if just APIs we can remove this part
                else
                {
                    u.UseUmbracoRuntimeMinificationEndpoints();
                }
    
                u.UseWebsiteEndpoints();
            });
    

    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:

Draft