Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • seanrock 241 posts 462 karma points
    Jan 27, 2020 @ 12:12
    seanrock
    0

    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

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Feb 06, 2020 @ 07:09
    Marc Goodson
    100

    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

  • seanrock 241 posts 462 karma points
    Feb 06, 2020 @ 07:35
    seanrock
    0

    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... what is displayed in the backoffice when custom url is returned from GetUrl

    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...

    GetOtherUrls overriden shows custom url

    I guess its better than having the wrong url, but still looks confusing for an editor.

    Maybe I'm missing something.

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Feb 10, 2020 @ 18:37
    Marc Goodson
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft