Copied to clipboard

Flag this post as spam?

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

  • schlubadub 102 posts 617 karma points
    May 26, 2015 @ 07:36

    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:

    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 or 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?

  • schlubadub 102 posts 617 karma points
    May 26, 2015 @ 09:01

    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
  • René Pjengaard 114 posts 675 karma points c-trib
    Nov 28, 2015 @ 21:13
    René Pjengaard

    Hi Schlubadub,

    did you ever find a better way to do this? Could you maybe use this?



Please Sign in or register to post replies

Write your reply to: