#Finding the home node

1 messages · Page 1 of 1 (latest)

nocturne shale
#

Hi

I have an Umbraco 13 with a structure like this

Website(primary)
Site A
Site B

Website(secondary)

Website(tertiary)

When the user arrives to any level I want to get some content which is on Website(primary).

At the moment I have managed to partially do this by using the domains service but this doesn't seem to work fully.

How could I always get to the primary website no matter how I reach the site?

Thank you

errant vector
#

Hi there! Assuming your Website nodes are in the root of the content tree, you could simply access the ContentAtRoot from an UmbracoContext. In controllers and views, you usually have access to Umbraco context, but you can also find it with IUmbracoContextAccessor.

#

I think ContentAtRoot returns the root content in the order that you see them in the backoffice, but it may be appropriate to give your primary site some distinct property by which you can recognize it.

nocturne shale
errant vector
#

Do you have access to an Umbraco context?

#

From the top of my head, it's:

var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
var contentAtRoot = umbracoContext.Content.GetContentAtRoot();
nocturne shale