Change or remove the Links from nodes when UmbracoVirtualNodeRouteHandler is used to intercept requests
Hello
Is it possible to either remove the Links from nodes in the back office or change them? I am using UmbracoVirtualNodeRouteHandler to render some content from a custom route however the Links for those nodes are showing the location within the content tree. If I cannot correct them to include my custom route I'd like to remove them to stop the client clicking the link thinking they're going to be taken to the custom page.
Yes you can! - you would need to implement a custom IUrlProvider, and register this with Umbraco's collection of UrlProviders before the default UrlProvider.
I would suggest creating a c# class that inherits from the existing DefaultUrlProvider - and then override GetUrl - check whether the underlying document type is of a type that is handled differently by the routing and provide your implementation, if not call the base implementation of GetUrl...
Thanks Marc! This does allow me to add the correct url however it still doesn't do exactly what I want.
I've inherited from the DefaultUrlProvider and overridden the GetUrl method as the link suggests. That does provide the correct url in code as stated. However, and here is the problem, the backoffice also calls GetUrl() but it doesn't like the url so it displays a message...
I have a route registered and the front displays the correct content.
I haven't found a way to correct that or the reason why it shows that message.
The only way I've found to show the url I need is overriding the GetOtherUrls method. But this isn't perfect either, because I still get the warning message...
I guess its better than having the wrong url, but still looks confusing for an editor.
Umbraco is complaining here that it tried to find the content using all the registered IContentFinders and couldn't find any content at all based on the Url generated by the new UrlProvider...
So essentially... if you have content in Umbraco that you just want to change the url routing to... you can 'just' use an IContentFinder + UrlProvider.
If however you have content outside of Umbraco that you want to display 'as if' it were inside Umbraco, or amalgamate with some bits of Umbraco Content then using a CustomRoute + UmbracoVirtualNodeRouteHandler... can make more sense...
In some really complicated circumtances you might use all of the above...
so If you don't have a compelling reason to use the UmbracoVirtualNodeRouteHandler, you could remove it and implement an IContentFinder, then your 'could not be routed' message would disappear...
... or to make the message go away keeping your handler you could add an IContentFinder that implemented the same logic of matching the Url to the content item as in the VirtualNodeRouteHandler...
... alternatively in your UrlProvider, don't override GetUrl - allow this to be the default Url for the content item, and instead provide an implementation for OtherUrls for the custom route... so at least you don't get the message - although the editor will see the 'default url' which might be equally unhelpful...
Change or remove the Links from nodes when UmbracoVirtualNodeRouteHandler is used to intercept requests
Hello
Is it possible to either remove the Links from nodes in the back office or change them? I am using UmbracoVirtualNodeRouteHandler to render some content from a custom route however the Links for those nodes are showing the location within the content tree. If I cannot correct them to include my custom route I'd like to remove them to stop the client clicking the link thinking they're going to be taken to the custom page.
Thanks Sean
Hi seanrock
Yes you can! - you would need to implement a custom IUrlProvider, and register this with Umbraco's collection of UrlProviders before the default UrlProvider.
https://our.umbraco.com/Documentation/Reference/Routing/Request-Pipeline/outbound-pipeline#defaulturlprovider
I would suggest creating a c# class that inherits from the existing DefaultUrlProvider - and then override GetUrl - check whether the underlying document type is of a type that is handled differently by the routing and provide your implementation, if not call the base implementation of GetUrl...
regards
Marc
Thanks Marc! This does allow me to add the correct url however it still doesn't do exactly what I want.
I've inherited from the DefaultUrlProvider and overridden the GetUrl method as the link suggests. That does provide the correct url in code as stated. However, and here is the problem, the backoffice also calls GetUrl() but it doesn't like the url so it displays a message...
I have a route registered and the front displays the correct content. I haven't found a way to correct that or the reason why it shows that message.
The only way I've found to show the url I need is overriding the GetOtherUrls method. But this isn't perfect either, because I still get the warning message...
I guess its better than having the wrong url, but still looks confusing for an editor.
Maybe I'm missing something.
Hi seanrock
Umbraco uses a series of IContentFinders to map incoming request for a Url to a piece of content...
https://our.umbraco.com/Documentation/Reference/Routing/Request-Pipeline/IContentFinder
Umbraco is complaining here that it tried to find the content using all the registered IContentFinders and couldn't find any content at all based on the Url generated by the new UrlProvider...
So essentially... if you have content in Umbraco that you just want to change the url routing to... you can 'just' use an IContentFinder + UrlProvider.
If you prefer to build a custom Model, MVC style in this scenario you can still use RouteHijacking by Doc Type Alias: https://our.umbraco.com/Documentation/Reference/Routing/custom-controllers
If however you have content outside of Umbraco that you want to display 'as if' it were inside Umbraco, or amalgamate with some bits of Umbraco Content then using a CustomRoute + UmbracoVirtualNodeRouteHandler... can make more sense...
In some really complicated circumtances you might use all of the above...
so If you don't have a compelling reason to use the UmbracoVirtualNodeRouteHandler, you could remove it and implement an IContentFinder, then your 'could not be routed' message would disappear...
... or to make the message go away keeping your handler you could add an IContentFinder that implemented the same logic of matching the Url to the content item as in the VirtualNodeRouteHandler...
... alternatively in your UrlProvider, don't override GetUrl - allow this to be the default Url for the content item, and instead provide an implementation for OtherUrls for the custom route... so at least you don't get the message - although the editor will see the 'default url' which might be equally unhelpful...
regards
Marc
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.