Copied to clipboard

Flag this post as spam?

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


  • John Churchley 272 posts 1258 karma points c-trib
    Feb 14, 2018 @ 12:48
    John Churchley
    0

    Url without Domain

    Hi,

    I'm trying to create a custom routes for a package dynamically in a ApplicationEventHandler. I'm trying to use existing node url to form the route. However when I use the Umbraco Helper

       var pageData  umbracoHelper.ContentQuery.TypedContent(page.Id); 
    

    pageData.Url returns the absolute I'm trying to get the relative url to the domain.

    I was thinking of an extension method which removes the host but wondered if there was a native method?

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Feb 14, 2018 @ 15:50
    Alex Skrypnyk
    0

    Hi John

    It looks like "useDomainPrefixes" is set to true in your solution.

    You can change it in /config/umbracoSettings.config

    /Alex

  • John Churchley 272 posts 1258 karma points c-trib
    Feb 14, 2018 @ 15:54
    John Churchley
    2

    Hi Alex,

    "useDomainPrefixes" is set to false thanks for the suggestion. I ended up using an exension method with the following code:

       Uri myUri = new Uri(pageData.Url());
       pageUrl = myUri.AbsolutePath.TrimStart("/");
    

    John

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Feb 16, 2018 @ 08:20
    Alex Skrypnyk
    0

    Hi John

    Thanks for sharing the solution, have a great day

    /Alex

  • Jakob Bagterp 13 posts 115 karma points c-trib
    May 18, 2023 @ 16:19
    Jakob Bagterp
    1

    Have you tried this method?

    Model.Url(mode: UrlMode.Relative)
    

    For instance, the relative part is /some/page of an absolute URL https://www.example.com/some/page, which you can get by setting the mode to UrlMode.Absolute.

    Find more info in the documentation.

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

Please Sign in or register to post replies