SiteMap.CurrentNode 属性   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个表示当前被请求的页的 SiteMapNode 控件。
public:
 static property System::Web::SiteMapNode ^ CurrentNode { System::Web::SiteMapNode ^ get(); };public static System.Web.SiteMapNode CurrentNode { get; }static member CurrentNode : System.Web.SiteMapNodePublic Shared ReadOnly Property CurrentNode As SiteMapNode属性值
表示当前被请求的页的 SiteMapNode 实例;如果站点地图信息中不存在代表节点,则为 null。
例外
未启用站点地图功能。
配置中指定的默认提供程序不存在。
只有在低信任或以上设置的情况下运行时,才支持此功能。
示例
下面的代码示例演示如何使用 CurrentNode 属性检索 SiteMapNode 表示当前页的对象。
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
    // Examine the CurrentNode, and navigate the SiteMap relative to it.
    Response.Write(SiteMap.CurrentNode.Title + "<br />");
    Response.Write("<font COLOR='red'>" + SiteMap.CurrentNode.Url + "</font><br />");
    // What nodes are children of the CurrentNode?
    if (SiteMap.CurrentNode.HasChildNodes) {
        IEnumerator childNodesEnumerator = SiteMap.CurrentNode.ChildNodes.GetEnumerator();
        while (childNodesEnumerator.MoveNext()) {
            // Prints the Title of each node.
            Response.Write(childNodesEnumerator.Current.ToString() + "<br />");
        }
    }
    Response.Write("<hr />");
    // Examine the RootNode, and navigate the SiteMap relative to it.
    Response.Write(SiteMap.RootNode.Title + "<br />");
    Response.Write(SiteMap.RootNode.Url + "<br />");
    // What nodes are children of the RootNode?
    if (SiteMap.RootNode.HasChildNodes) {
        IEnumerator rootNodesChildrenEnumerator = SiteMap.RootNode.ChildNodes.GetEnumerator();
        while (rootNodesChildrenEnumerator.MoveNext()) {
            // Prints the Title of each node.
            Response.Write(rootNodesChildrenEnumerator.Current.ToString() + "<br />");
        }
    }
}
</script>
<script runat="server">
Private Sub Page_Load(sender As Object, e As EventArgs)
    ' Examine the CurrentNode, and navigate the SiteMap relative to it.
    Response.Write(SiteMap.CurrentNode.Title & "<br />")
    Response.Write("<font COLOR='red'>" & SiteMap.CurrentNode.Url & "</font><br />")
    ' What nodes are children of the CurrentNode?
    If (SiteMap.CurrentNode.HasChildNodes) Then
        Dim ChildNodesEnumerator As IEnumerator = SiteMap.CurrentNode.ChildNodes.GetEnumerator()
        While (ChildNodesEnumerator.MoveNext())
            ' Prints the Title of each node.
            Response.Write(ChildNodesEnumerator.Current.ToString() & "<br />")
        End While
    End If
    Response.Write("<hr />")
    ' Examine the RootNode, and navigate the SiteMap relative to it.
    Response.Write(SiteMap.RootNode.Title & "<br />")
    Response.Write(SiteMap.RootNode.Url & "<br />")
    ' What nodes are children of the RootNode?
    If (SiteMap.RootNode.HasChildNodes) Then
        Dim RootNodesChildrenEnumerator As IEnumerator = SiteMap.RootNode.ChildNodes.GetEnumerator()
        While (RootNodesChildrenEnumerator.MoveNext())
            ' Prints the Title of each node.
            Response.Write(RootNodesChildrenEnumerator.Current.ToString() & "<br />")
        End While
    End If
End Sub ' Page_Load
</script>
注解
类 SiteMap 通过从提供程序请求属性来检索 CurrentNode 该属性。
如果站点地图信息中页面不存在具有代表性的节点,或者如果启用了安全修整,并且无法为当前用户返回该节点, null 则返回 。
SiteMapResolve如果存在一个或多个订阅,则默认站点地图提供程序将引发该事件。
如果实现自己的 SiteMapProvider 对象,则可以创建自己的机制来查找和检索 CurrentNode。 但是,如果扩展 StaticSiteMapProvider 类并使用基于 URL 的方案来标识页面,则可以重写 FindSiteMapNode 方法。