Getting the name of the current (page's) root node in C#?
Hi, search as I may, it's a needle in a hay stack for API newbies. I have a Macro (xslt) that uses an <XsltExtensions> written in C# quite successfully. I can get at the dictionary but I cant figure out how to get that the current root node (name) in my content hierarchy. I can get it in XSLT (horror :-) but wheres the API in C# ? While I'm at it :-) if you happen to know how to then best redirect to another top level page via the API? Or do I just use standard ASP.NET Request.Redirect() or Server.Transfer()?
As you can see, this gets you an array of domains (you may have more than one). The Domain object has a RootNodeId that is the Id of the node where the domain is attached.
For redirecting, you just use the Request.Redirect() as you suggest.
If you specify a property on your page called umbracoUrlRedirect and set it as a Content Picker type, Umbraco will automatically redirect to the node specified for you (done by ID, so even if the target page name changes, you don't lose any SEO).
Getting the name of the current (page's) root node in C#?
Hi, search as I may, it's a needle in a hay stack for API newbies. I have a Macro (xslt) that uses an <XsltExtensions> written in C# quite successfully. I can get at the dictionary but I cant figure out how to get that the current root node (name) in my content hierarchy. I can get it in XSLT (horror :-) but wheres the API in C# ? While I'm at it :-) if you happen to know how to then best redirect to another top level page via the API? Or do I just use standard ASP.NET Request.Redirect() or Server.Transfer()?
Thanks!
R
R
Hi Richard
The place to go in the API is umbraco.presentation.nodeFactory.
You would get the current node like this:
You can then do a recursive method that looks at the current.Parent property. When the Parent.Id is -1 you are at the root node.
If you are using domains, you can use this method:
As you can see, this gets you an array of domains (you may have more than one). The Domain object has a RootNodeId that is the Id of the node where the domain is attached.
For redirecting, you just use the Request.Redirect() as you suggest.
Richard,
If you specify a property on your page called umbracoUrlRedirect and set it as a Content Picker type, Umbraco will automatically redirect to the node specified for you (done by ID, so even if the target page name changes, you don't lose any SEO).
Hope this helps.
Benjamin
is working on a reply...