Say you have an Umbraco installation with two sites with their respective Homepages and Pages, e.g
Content (-1)
Homepage 1 (1000)
Page 1.1 (1001)
Homepage 2 (1002)
Page 2.1 (1003)
In C# the current node can be obtained with
Node currentNode = Node.GetCurrent();
and its corresponding home node can be found with
Node currentHome = new Node(int.Parse(currentNode.Path.Split(',')[1]));
Now, currentNode.Path returns a string of comma separated integers that starts with -1, i.e. the root, the master root as you called it, under which all Homepages 'live'.
E.g. the path value of Page 2.1 is "-1,1002,1003". When split at the comma, you'll end up with an array with 3 elements indexed 0,1,2. Now, the second one, with index 1 will give the id of the home node. As you can see, the last id is the id of the current node. As an aside, the indexes also tell the level of the node, so the level of a Homepage is 1.
I used the following script on a template that was used on an intranet/extranet and has protected pages. When a visitor follows a link to a protected page, he/she is denied access and redirected to the homepage, which has a member login.
Getting the home node using c#
Hi guys,
I need to find the home node (type homepage) using c# on a multisite installation of umbraco.
I cant find any examples of this anywhere. Any help would be much appreciated.
Thanks
Scott
Hi SinkyPars,
How about:
or if you have uComponents installed, how about this:
or
HTH,
Hendy
Just posted this as an answer to http://stackoverflow.com/questions/12643537/is-there-a-way-to-return-the-current-site-node-id-via-the-api-in-umbraco
Say you have an Umbraco installation with two sites with their respective Homepages and Pages, e.g
In C# the current node can be obtained with
and its corresponding home node can be found with
Now,
currentNode.Path
returns a string of comma separated integers that starts with -1, i.e. the root, the master root as you called it, under which all Homepages 'live'.E.g. the path value of Page 2.1 is "-1,1002,1003". When split at the comma, you'll end up with an array with 3 elements indexed 0,1,2. Now, the second one, with index 1 will give the id of the home node. As you can see, the last id is the id of the current node. As an aside, the indexes also tell the level of the node, so the level of a Homepage is 1.
I used the following script on a template that was used on an intranet/extranet and has protected pages. When a visitor follows a link to a protected page, he/she is denied access and redirected to the homepage, which has a member login.
Cheers,
León
is working on a reply...