SiteMap.CurrentNode Property
Gets a SiteMapNode control that represents the currently requested page.
Assembly: System.Web (in System.Web.dll)
Property Value
Type: System.Web.SiteMapNodeA SiteMapNode instance that represents the currently requested page; otherwise, null, if no representative node exists in the site map information.
| Exception | Condition |
|---|---|
| InvalidOperationException | The site map feature is not enabled. |
| ConfigurationErrorsException | The default provider specified in the configuration does not exist. |
| HttpException | The feature is supported only when running in Low trust or higher. |
The SiteMap class retrieves the CurrentNode property by requesting it from the provider.
If no representative node exists for the page in the site map information, or if security trimming is enabled and the node cannot be returned for the current user, null is returned.
The SiteMapResolve event is raised by the default site map provider if one or more subscriptions exist.
If you implement your own SiteMapProvider object, you might create your own mechanism to find and retrieve the CurrentNode. However, if you extend the StaticSiteMapProvider class and use a URL-based scheme to identify pages, you can override the FindSiteMapNode method.
The following code example demonstrates how to use the CurrentNode property to retrieve the SiteMapNode object that represents the current page.
<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>
Available since 2.0