Copied to clipboard

Flag this post as spam?

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


  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jun 17, 2014 @ 20:42
    Martin Griffiths
    1

    Get root node id from domain name (request.url)

    Does anyone know if there's any way you can take the current url (lets say using Request.Url) and pass in the hostname into an API than will return me the Umbraco root ID to which it is applied?

    I guess the opposite of NiceUrlWithDomain(int id) where you know the id and get the url back.

    Thanks Martin

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jun 17, 2014 @ 21:03
    Dirk De Grave
    0

    I *think* you can get it from 

    UmbracoContext.Current.PublishedContentRequest.Domain.RootNodeId 

    from either view or controller (Haven't tried it tbh though)

    /Dirk

     

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 17, 2014 @ 21:24
    Jeavon Leopold
    0

    I once used the method in this Gist but I wonder if there is a newer and better way....

  • Stephen 767 posts 2273 karma points c-trib
    Jun 17, 2014 @ 21:51
    Stephen
    2

    If we're talking about the current url then Dirk is right and UmbracoContext.Current.PublishedContentRequest.Domain will give you the corresponding domain (if any) from which you can get the RootNodeId.

    If we're talking "any domain" then not sure you need @Jeavon's classes as you can do umbraco.cms.businesslogic.web.Domain.GetDomains() which will give you all domains (and cache the result for a few minutes). There's also a Domain.GetDomain(string name) method but beware: it will return the configured domain matching "name" exactly, so example.com would not match www.example.com.

    Making sense?

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jun 18, 2014 @ 00:00
    Martin Griffiths
    0

    Hi all

    Thanks all for your help. I'm developing a small chunk of fixed functionality using custom routes. This keeps it from being messed with in the back office, but doesn't match any published content. I still need to be able to render all of the front end UI for content that is in the CMS. So I need to get the root node for the site which is tied to the domain as it's a multi site build. 

    Stephan do you know what library I use for Domain.GetDomain ?

    Thanks Martin

  • Stephen 767 posts 2273 karma points c-trib
    Jun 18, 2014 @ 08:13
    Stephen
    1

    The Domain class is in the umbraco.cms project, ie the cms.dll library.

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jun 18, 2014 @ 09:15
    Martin Griffiths
    0

    Lol sorry Stephan you did put the entire namespace. Thanks I'll check it out today.  Martin

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jun 18, 2014 @ 15:54
    Martin Griffiths
    0

    Hi Stephan

    The Domain class worked perfectly, alhough i'm a little concerned that it's quite an old call? Hopefully I won't find it deprecated any time soon!

    Thanks very much for your help.

    Martin.

  • Stephen 767 posts 2273 karma points c-trib
    Jun 18, 2014 @ 15:56
    Stephen
    0

    It'll get deprecated but not so soon, and even then it will remain available for some time, so I'd say you are safe.

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jun 18, 2014 @ 15:59
    Martin Griffiths
    0

    Could it be added to TypedContent(string url) ? Which returns IPublishedContent for the rootNodeId?

Please Sign in or register to post replies

Write your reply to:

Draft