SiteMap.SiteMapResolve Evento

Definición

Se produce cuando se tiene acceso a la propiedad CurrentNode.

public:
 static event System::Web::SiteMapResolveEventHandler ^ SiteMapResolve;
public static event System.Web.SiteMapResolveEventHandler SiteMapResolve;
member this.SiteMapResolve : System.Web.SiteMapResolveEventHandler 
Public Shared Custom Event SiteMapResolve As SiteMapResolveEventHandler 

Tipo de evento

Ejemplos

En el ejemplo de código siguiente se muestra cómo controlar el SiteMapResolve evento en una página web de ASP.NET para modificar las direcciones URL de destino que muestra un control de navegación del sitio, como el SiteMapPath control . En este ejemplo, la página actual es una página de publicación en un panel de boletines en línea o foro. Para representar la navegación del sitio más significativa, las direcciones URL de los nodos que muestra el control de navegación se anexan con cadenas de consulta relevantes para el contexto.

Nota

La infraestructura de navegación del sitio ASP.NET protege contra la recursividad infinita, lo que proporciona una protección y minimiza el riesgo de seguridad asociado al acceso a la CurrentNode propiedad desde dentro de la SiteMapResolveEventHandler clase .

El código siguiente pertenece al archivo Global.asax. El controlador de eventos solo se asociará una vez para la aplicación. El código reconoce si la página implementa la ISiteMapResolver interfaz . Si se implementa la interfaz, se llama a la ExpandForumPaths función .

private void Page_Load(object sender, EventArgs e)
{
    // The ExpandForumPaths method is called to handle
    // the SiteMapResolve event.
    SiteMap.SiteMapResolve +=
      new SiteMapResolveEventHandler(this.ExpandForumPaths);
}

private SiteMapNode ExpandForumPaths(Object sender, SiteMapResolveEventArgs e)
{
    // The current node represents a Post page in a bulletin board forum.
    // Clone the current node and all of its relevant parents. This
    // returns a site map node that a developer can then
    // walk, modifying each node.Url property in turn.
    // Since the cloned nodes are separate from the underlying
    // site navigation structure, the fixups that are made do not
    // effect the overall site navigation structure.
    SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
    SiteMapNode tempNode = currentNode;

    // Obtain the recent IDs.
    int forumGroupID = GetMostRecentForumGroupID();
    int forumID = GetMostRecentForumID(forumGroupID);
    int postID = GetMostRecentPostID(forumID);

    // The current node, and its parents, can be modified to include
    // dynamic querystring information relevant to the currently
    // executing request.
    if (0 != postID)
    {
        tempNode.Url = tempNode.Url + "?PostID=" + postID.ToString();
    }

    if ((null != (tempNode = tempNode.ParentNode)) &&
        (0 != forumID))
    {
        tempNode.Url = tempNode.Url + "?ForumID=" + forumID.ToString();
    }

    if ((null != (tempNode = tempNode.ParentNode)) &&
        (0 != forumGroupID))
    {
        tempNode.Url = tempNode.Url + "?ForumGroupID=" + forumGroupID.ToString();
    }

    return currentNode;
}
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    ' The ExpandForumPaths method is called to handle
    ' the SiteMapResolve event.
    AddHandler SiteMap.SiteMapResolve, AddressOf Me.ExpandForumPaths

End Sub

Private Function ExpandForumPaths(ByVal sender As Object, ByVal e As SiteMapResolveEventArgs) As SiteMapNode
    ' The current node represents a Post page in a bulletin board forum.
    ' Clone the current node and all of its relevant parents. This
    ' returns a site map node that a developer can then
    ' walk, modifying each node.Url property in turn.
    ' Since the cloned nodes are separate from the underlying
    ' site navigation structure, the fixups that are made do not
    ' effect the overall site navigation structure.
    Dim currentNode As SiteMapNode = SiteMap.CurrentNode.Clone(True)
    Dim tempNode As SiteMapNode = currentNode

    ' Obtain the recent IDs.
    Dim forumGroupID As Integer = GetMostRecentForumGroupID()
    Dim forumID As Integer = GetMostRecentForumID(forumGroupID)
    Dim postID As Integer = GetMostRecentPostID(forumID)

    ' The current node, and its parents, can be modified to include
    ' dynamic querystring information relevant to the currently
    ' executing request.
    If Not (0 = postID) Then
        tempNode.Url = tempNode.Url & "?PostID=" & postID.ToString()
    End If

    tempNode = tempNode.ParentNode
    If Not (0 = forumID) And Not (tempNode Is Nothing) Then
        tempNode.Url = tempNode.Url & "?ForumID=" & forumID.ToString()
    End If

    tempNode = tempNode.ParentNode
    If Not (0 = ForumGroupID) And Not (tempNode Is Nothing) Then
        tempNode.Url = tempNode.Url & "?ForumGroupID=" & forumGroupID.ToString()
    End If

    Return currentNode

End Function

El código siguiente define una interfaz independiente. (En un proyecto de sitio web, puede colocar este código en la carpeta App_Code). La ISiteMapResolver interfaz define el ExpandForumPaths método .

// These methods are just placeholders for the example.
// One option is to use the HttpContext or e.Context object
// to obtain the ID.
private int GetMostRecentForumGroupID()
{
    return 24;
}

private int GetMostRecentForumID(int forumGroupId)
{
    return 128;
}

private int GetMostRecentPostID(int forumId)
{
    return 317424;
}
' These methods are just placeholders for the example.
' One option is to use the HttpContext or e.Context object
' to obtain the ID.
Private Function GetMostRecentForumGroupID() As Integer
    Return 24
End Function

Private Function GetMostRecentForumID(ByVal forumGroupId As Integer) As Integer
    Return 128
End Function

Private Function GetMostRecentPostID(ByVal forumId As Integer) As Integer
    Return 317424
End Function

El código siguiente pertenece a la página que es al menos tres nodos en profundidad en la estructura del mapa de sitio. La página implementa la ISiteMapResolver interfaz , que permite ExpandForumPaths llamar al método .

<asp:SiteMapPath
id="SiteMapPath1"
runat="server"
RenderCurrentNodeAsLink="true" />
<asp:SiteMapPath
id="SiteMapPath1"
runat="server"
RenderCurrentNodeAsLink="true" />

Comentarios

Los suscriptores adjuntan un SiteMapResolveEventHandler objeto al evento estático SiteMapResolve para recibir una notificación cuando se accede a la CurrentNode propiedad. Esto permite al usuario implementar lógica personalizada al crear una SiteMapNode representación de la página que se está ejecutando actualmente sin necesidad de una implementación del proveedor personalizado.

Si se suscribe al SiteMapResolve evento, también se suscribe al SiteMapResolve evento en el proveedor de mapa de sitio predeterminado.

Se aplica a

Consulte también