Copied to clipboard

Flag this post as spam?

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


  • Damien Holley 179 posts 540 karma points
    Nov 05, 2020 @ 01:25
    Damien Holley
    0

    How to rewrite URL in codebehind

    I need to make all links in a particular path tree relative, we figured we could do this by using URL rewrite, however it would be good to be able to find the subdomain's path regardless of what is is to enact this rewrite and I am unsure of how to about it.

    so if the link of a href is alt.domain.com/biscuits/donkey it gets rewritten as /biscuits/donkey.

    that way if subd is using the menu from alt, then the links to any non-local tree node are changed to be local and relative. ie: a link on a page under subd = "alt.domain.com/biscuits/donkey" gets changed to "/biscuits/donkey"

    Unsure if I would need to make a plugin or if this should be simple from elsewhere, but I want to do it in codebehind so I can find the asbolute URL of alt.domain.com from the node, so that if a change is made, everything keeps working properly. This also means not having a magicstring in the web.config rewriting from there.

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Nov 06, 2020 @ 09:38
    Søren Gregersen
    0

    hi,

    I would suggest you just remove the domain when rendering the urls.

    It would likely need some kind of content finder since you either need to add all the domains to the parent / root, if you need the content to be routable on those other urls. Have a look at the documentation her https://our.umbraco.com/documentation/Reference/Routing/Request-Pipeline/IContentFinder

    HTH :)

    also, codebehind was a term used in asp.net forms - not used in asp.net mvc :)

  • Damien Holley 179 posts 540 karma points
    Nov 14, 2020 @ 07:56
    Damien Holley
    100

    We used razor to hit a string extension for all the components requiring changing, this extension finds out if the particular URL used in a link is relevant, then strips out the website address, making it relative.

    the IContentFinder in this instance is not really appropriate and adds unnecessary complication, thanks for the suggestion though.

    codebehind is a term used in Xamarin, generic .NET and other frameworks still.

Please Sign in or register to post replies

Write your reply to:

Draft