SiteMap.CurrentNode 屬性

定義

取得 SiteMapNode 控制項,表示目前要求的網頁。

public:
 static property System::Web::SiteMapNode ^ CurrentNode { System::Web::SiteMapNode ^ get(); };
public static System.Web.SiteMapNode CurrentNode { get; }
static member CurrentNode : System.Web.SiteMapNode
Public 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>

備註

類別 SiteMapCurrentNode 藉由向提供者要求屬性來擷取屬性。

如果網站地圖資訊中頁面沒有代表節點存在,或已啟用安全性調整,而且無法傳回目前使用者的節點, null 則會傳回。

如果有一或多個訂用帳戶存在,預設 SiteMapResolve 網站地圖提供者就會引發此事件。

如果您實作自己的 SiteMapProvider 物件,您可以建立自己的機制來尋找和擷取 CurrentNode 。 不過,如果您擴充 StaticSiteMapProvider 類別並使用以 URL 為基礎的配置來識別頁面,則可以覆寫 FindSiteMapNode 方法。

適用於

另請參閱