Umbraco – 在C#中查找根节点

我正在研究后端模块,因此Node.GetCurrent()不是一个选项。 我需要找到一种方法来调用Node currentNode = new Node(parentNodeId); 并获取该站点的根节点。 我在XSLT中看过样本,但C#没有。 有谁知道我怎么能做到这一点?

即使只是获取根节点的ID以便我可以调用new Node()也会很棒。

根节点始终可用:

 var rootNode = new Node(-1); 

Umbraco 7的更新(也可以在早期版本中使用)

 @{ var siteroot = CurrentPage.AncestorOrSelf(1); } 

有关详细信息,请查看文档 – > http://our.umbraco.org/Documentation/Reference/Querying/DynamicNode/Collections

布伦南是对的,

 var rootNode = new DynamicNode(-1); 

也行得通!

Umbraco 6+的更新

 public static IPublishedContent GetRootNode() { var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); var rootNode = umbracoHelper.TypedContentSingleAtXPath("//root")); return rootNode; } 

这只是一个文档类型别名,并使用当前的Umbraco上下文将根节点查找为IPublishedContent。 UmbracoHelper给你提供了很多选择。

Umbraco 7:

 Umbraco.TypedContentAtRoot();