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.
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.
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 ?
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
I *think* you can get it from
from either view or controller (Haven't tried it tbh though)
/Dirk
I once used the method in this Gist but I wonder if there is a newer and better way....
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?
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
The Domain class is in the umbraco.cms project, ie the cms.dll library.
Lol sorry Stephan you did put the entire namespace. Thanks I'll check it out today. Martin
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.
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.
Could it be added to TypedContent(string url) ? Which returns IPublishedContent for the rootNodeId?
is working on a reply...