I am trying to get the root node from a webforms page (the main umbraco site is MVC). I originally thought that this would solve my problem:
UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
int pageId = umbracoHelper.ContentAtRoot().FirstOrDefault().Id;
dynamic home = umbracoHelper.Content(pageId);
//Do stuff with home
But when I go to site1.mydomain.com.au/mypage.aspx or site2.mydomain.com.au/mypage.aspx the pageID is for the first site (site1).
Does anyone know how to return the home id for the current site? I assume Umbraco figures that out with the website URL or some other internal cleverness?
Okay, I have a solution that "works" but it looks really clumsy (see below). I'm still hoping that someone might know a better / more efficient solution?
using umbraco;
using umbraco.cms.businesslogic.web;
-----
int FoundNodeID = 0;
UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
foreach (var rootNode in umbracoHelper.ContentAtRoot())
{
int nodeID = rootNode.Id;
//Check against all possible domains (as rootNode.Url returns just the most recent domain entry)
Domain[] domains = library.GetCurrentDomains(nodeID);
foreach (Domain currentDomain in domains)
{
if (currentDomain.Name.ToLower() == Request.Url.Host.ToLower())
{
FoundNodeID = nodeID;
}
}
}
if (FoundNodeID != 0)
{
dynamic home = umbracoHelper.Content(FoundNodeID); //Do stuff } else { //Explode }
Root / Home Node incorrect in Multi-Site Setup
I am trying to get the root node from a webforms page (the main umbraco site is MVC). I originally thought that this would solve my problem:
But when I go to site1.mydomain.com.au/mypage.aspx or site2.mydomain.com.au/mypage.aspx the pageID is for the first site (site1).
Does anyone know how to return the home id for the current site? I assume Umbraco figures that out with the website URL or some other internal cleverness?
Okay, I have a solution that "works" but it looks really clumsy (see below). I'm still hoping that someone might know a better / more efficient solution?
Hi Schlubadub,
did you ever find a better way to do this? Could you maybe use this?
/René
is working on a reply...