Open dnwhte opened 4 years ago
Unfortunately it doesn't seem to work with GetByRoute().
I tried adding a custom route but GetByRoute won't pick it up. Other workarounds like using a custom content finder or manually registering a redirect won't work either (had to try though! :) )
Any ideas welcome.
Still no luck unfortunately. I ended up copying a lot of the code from the VirtualNodesContentFinder for my purposes, so I can at least utilize the cache.
I found that, for my case at least, GetSingleByXPath is faster than the query used at https://github.com/sotirisf/Umbraco-VirtualNodes/blob/master/VirtualNodes/VirtualNodesContentFinder.cs#L50. I'm on v7 though. I don't know that it will be the case on v8.
My method:
IEnumerable<string> pathSegments = contentRequest.Uri.AbsolutePath.Split('/').Where(s => !string.IsNullOrWhiteSpace(s));
string xpath = "/";
foreach (string seg in pathSegments)
{
xpath += "/*[@urlName='" + seg + "'][1]";
}
IPublishedContent item = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetSingleByXPath(xpath);
Always returns null when requesting a url that contains (or does not contain rather) a virtual node.
For example,
Any idea what's up with this? Or how to make it work with GetByRoute? Or an alternative w/o traversing the tree?