Copied to clipboard

Flag this post as spam?

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


  • Colin 46 posts 146 karma points
    Mar 31, 2020 @ 17:52
    Colin
    0

    How to get root URL?

    Hi

    My Umbraco installation is as follows

    SiteDefault
      - SiteTwo
      - SiteThree
      - Site Four
    

    I have a web user control. How could I retrieve the root URL for each site please?

    Thanks

  • Colin 46 posts 146 karma points
    Apr 01, 2020 @ 05:35
    Colin
    0

    When I enter this in my control I have a namespace error but I don't know which namespace I need to add. If this is the correct code does anyone know?

    node.UrlAbsolute();

    Thanks

  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    Apr 01, 2020 @ 06:38
    Dennis Adolfi
    0

    Hi Colin.

    Is your 'node' an IPublishedContent item? In that case you can use the extensionmethod .Site() like this:

    node.Site().Url;
    

    For this you need the Umbraco.Web namespace referenced: https://our.umbraco.com/apidocs/v7/csharp/api/Umbraco.Web.PublishedContentExtensions.html

  • Colin 46 posts 146 karma points
    Apr 02, 2020 @ 16:13
    Colin
    0

    Hi Dennis

    I'm trying this but I just can't get it to work on Umbraco 7.

    Word you mind giving me a full example as no matter what I try it didn't work but it would be a published node under the home node.

    OR even better without be to get the URL for the current page?

    Many thanks

  • Yakov Lebski 594 posts 2350 karma points
    Apr 02, 2020 @ 17:03
    Yakov Lebski
    0
    var root=Model.AncestorOrSelf(1)
    
  • 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