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
    schlubadub
    0

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

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

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

    Hi Schlubadub,

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

    UmbracoContext.Current.PublishedContentRequest.UmbracoDomain.RootContentId
    

    /René

  • 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