ContentLastChanceFinder and custom 404 error page issue when using custom routes
Hi,
I have an application where I have registered some MVC Routes independent of Umbraco. The issue here is that this causes the ContentLastChanceFinder to be fired because these routes do not have an IPublishedContent set.
The expected behaviour is that my custom route matches the right controller whereas now the ContentLastChanceFinder will set the 404 page as the IPublishedContent which for some reason causes the 404 page to be hit.
How can I somehow make my custom route to have precedence and it not hit the ContentLastChanceFinder, as I would expect it only to be hit if nothing was found in the Routing Table.
How do you handle 404 pages then? Via appsettings.json? If so could you check if the assignedcontent is also your 404 page?
You can do this anywhere via the IUmbracoContextAccesor and accessing PublishedRequest.PublishedContent
Because even if you don't specify your own LastChanceContentFinder umbraco seems to register one on it's own (If you specify the 404 page in appsettings.json at least)
ContentLastChanceFinder and custom 404 error page issue when using custom routes
Hi,
I have an application where I have registered some MVC Routes independent of Umbraco. The issue here is that this causes the ContentLastChanceFinder to be fired because these routes do not have an IPublishedContent set.
The expected behaviour is that my custom route matches the right controller whereas now the ContentLastChanceFinder will set the 404 page as the IPublishedContent which for some reason causes the 404 page to be hit.
How can I somehow make my custom route to have precedence and it not hit the ContentLastChanceFinder, as I would expect it only to be hit if nothing was found in the Routing Table.
Kind regards
Funnily enough we just had the same issue, and I was Googling and found your question.
At least for us we resolved it by looking at the order in which endpoints were registered.
We had this code in
Program.cs
:UseApplicationEndpoints
is our own extension method where we register custom routes.We fixed the problem by moving this method call before
u.UseWebsiteEndpoints();
Maybe that'll solve your issue too.
Andy
Hi Andy,
How did you register your custom routes?
I tried moving my custom code after UseBackOfficeEndpoints (so before UseWebsiteEndpoints) but to no avail.
Another question: do you have a LastChanceContentFinder? and if so does it hit the TryFindContent when navigating to your custom route?
Kind regards
The
UseApplicationEndpoints()
extension method looks like this:But not using a
LastChanceContentFinder
so perhaps your issue is different to the one we ran into.Hi Andy,
How do you handle 404 pages then? Via appsettings.json? If so could you check if the assignedcontent is also your 404 page?
You can do this anywhere via the IUmbracoContextAccesor and accessing PublishedRequest.PublishedContent
Because even if you don't specify your own LastChanceContentFinder umbraco seems to register one on it's own (If you specify the 404 page in appsettings.json at least)
is working on a reply...