Umbraco-CMS: XPath for 404 pages sometimes doesn't work in v13
What type of issue is it?
Wrong documentation
What article/section is this about?
https://github.com/umbraco/UmbracoDocs/blob/main/13/umbraco-cms/tutorials/custom-error-page.md
Describe the issue
The documentation provided for Error404Collection no longer works.
Bad example:
{ "Umbraco": { "CMS": { "Content": { "Error404Collection": [ { "Culture": "default", "ContentXPath": "//errorPages[@nodeName='My cool error']" } ] } } } }
It returns the error System.InvalidOperationException: XPathValue must be an XPathNavigator or a string. As I understand it, XPath support was removed from v13.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 37 (25 by maintainers)
@OwainJ Yes, now we’re talking! Thanks very much! With a reproduction in place it wasn’t too difficult to find the code that caused the problem. I’ve left a more extensive description of the problem (plus a fix) in PR https://github.com/umbraco/Umbraco-CMS/pull/16121
Thanks again, that was really helpful!
@BrionyMcKenz from v14 the alternative for ContentXPath is to use IContentLastChanceFinder, which can be used in v13 as well. You can see an example of how to use IContentLastChanceFinder here.
Fixed in https://github.com/umbraco/Umbraco-CMS/pull/16121 🚀
For anyone who wants to be able to support multiple-site-specific 404 Content nodes (as @anas1987 describes) and can’t wait for @nul800sebastiaan’s fix to be merged/released, or also wants to future-proof beyond XPath… I used the documentation example provided by @alina-tincas and created a version which supports the multi-site setup. Take a look here: Umbraco v13+ 404 Error IContentLastChanceFinder - Supporting multiple sites at root
The good news is:
"Error404Collection": [ { "Culture": "default", "ContentXPath": "$site/page404" } ],works in both 13.2.2 and 12.2.0 and it meets not found page in current culture@anas1987 That was going to be my next suggestion! 😉 Much, much easier to read as well if someone ever takes over that site! 👍
Thank you, @alina-tincas!
FYI: I tried as well with an upgrade from 12.3.6 and it’s still working for me too. Could it be that your XPath expression is not right somehow? I tried the error page being on level 2 (under “Home”) as well as on level 3 (under “Home” > “About us”) to make sure we didn’t break the
//part of the XPath selector.Of course if we broke it, it needs to be fixed but as noted a couple times above, we need a way to reproduce the problem. I can’t see anything obvious in the changes between 12 and 13 either that could’ve broken this, so for now there’s nowhere to start without a reproduction of the problem.
@andr317c, if “The current implementation of XPath is suboptimal and will be removed entirely in a future version. It is currently obsolete and scheduled for removal in v14.” will there be any way to target a 404 page outside of ID and GUID ID?
Currently, it’s very nice to know that we put our 404 page at /Page-Not-Found. So we don’t have to update it from project to project or instance to instance. I understand how to use the ID and GUID ID. Will those be our only options in Umbraco14?
For us, this post here from @marcemarc helped: https://our.umbraco.com/forum/using-umbraco-and-getting-started/113342-xpathvalue-must-be-an-xpathnavigator-or-a-string#comment-349382
Thus this working setup for our multisite (literally changed from
//to/and it fixed it. Oddly, our 404 pages were working on every site except one, but this slash change resolved the one that wasn’t working and left the others functional as well.I’ve tested this on a fresh install of Umbraco 13.0.3. I was able to get the
Error404Collectionconfig to work with the following settings:Where my 404 page’s document type alias was
myErrorDocumentType, and the node’s name was404 Page Not Found