SiteMap.CurrentNode Propriedade

Definição

Obtém um controle SiteMapNode que representa a página atualmente solicitada.Gets a SiteMapNode control that represents the currently requested page.

public:
 static property System::Web::SiteMapNode ^ CurrentNode { System::Web::SiteMapNode ^ get(); };
public static System.Web.SiteMapNode CurrentNode { get; }
member this.CurrentNode : System.Web.SiteMapNode
Public Shared ReadOnly Property CurrentNode As SiteMapNode

Valor da propriedade

SiteMapNode

Uma instância SiteMapNode que representa a página atualmente solicitada; caso contrário, null, se não existir nenhum nó representativo nas informações de mapa do site.A SiteMapNode instance that represents the currently requested page; otherwise, null, if no representative node exists in the site map information.

Exceções

O recurso de mapa do site não está habilitado.The site map feature is not enabled.

O provedor padrão especificado na configuração não existe.The default provider specified in the configuration does not exist.

O recurso tem suporte apenas quando está em execução em Confiança baixa ou níveis superiores.The feature is supported only when running in Low trust or higher.

Exemplos

O exemplo de código a seguir demonstra como usar a CurrentNode propriedade para recuperar o SiteMapNode objeto que representa a página atual.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 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>

Comentários

A SiteMap classe recupera a CurrentNode Propriedade solicitando-a do provedor.The SiteMap class retrieves the CurrentNode property by requesting it from the provider.

Se não existir nenhum nó representativo para a página nas informações do mapa do site, ou se a remoção de segurança estiver habilitada e o nó não puder ser retornado para o usuário atual, null será retornado.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.

O SiteMapResolve evento é gerado pelo provedor de mapa do site padrão se uma ou mais assinaturas existirem.The SiteMapResolve event is raised by the default site map provider if one or more subscriptions exist.

Se você implementar seu próprio SiteMapProvider objeto, poderá criar seu próprio mecanismo para localizar e recuperar o CurrentNode .If you implement your own SiteMapProvider object, you might create your own mechanism to find and retrieve the CurrentNode. No entanto, se você estender a StaticSiteMapProvider classe e usar um esquema baseado em URL para identificar páginas, poderá substituir o FindSiteMapNode método.However, if you extend the StaticSiteMapProvider class and use a URL-based scheme to identify pages, you can override the FindSiteMapNode method.

Aplica-se a

Confira também