SiteMapResolveEventHandler SiteMapResolveEventHandler SiteMapResolveEventHandler SiteMapResolveEventHandler Delegate

Definizione

Rappresenta il metodo che gestirà l'evento SiteMapResolve di una specifica istanza della classe SiteMapProvider o della classe SiteMap statica.Represents the method that will handle the SiteMapResolve event of a specific instance of the SiteMapProvider or static SiteMap class.

public delegate System::Web::SiteMapNode ^ SiteMapResolveEventHandler(System::Object ^ sender, SiteMapResolveEventArgs ^ e);
public delegate System.Web.SiteMapNode SiteMapResolveEventHandler(object sender, SiteMapResolveEventArgs e);
type SiteMapResolveEventHandler = delegate of obj * SiteMapResolveEventArgs -> SiteMapNode
Public Delegate Function SiteMapResolveEventHandler(sender As Object, e As SiteMapResolveEventArgs) As SiteMapNode 

Parametri

sender
Object Object Object Object

Origine dell'evento, un'istanza della classe SiteMapProvider.The source of the event, an instance of the SiteMapProvider class.

Valore restituito

System.Web.SiteMapNode

Elemento SiteMapNode che rappresenta il risultato dell'operazione SiteMapResolveEventHandler.The SiteMapNode that represents the result of the SiteMapResolveEventHandler operation.

Ereditarietà
SiteMapResolveEventHandlerSiteMapResolveEventHandlerSiteMapResolveEventHandlerSiteMapResolveEventHandler

Esempi

Nell'esempio di codice seguente viene illustrato come gestire SiteMapResolve l'evento in una pagina Web ASP.NET per modificare gli URL di destinazione visualizzati da un controllo di navigazione del sito, ad SiteMapPath esempio il controllo.The following code example demonstrates how to handle the SiteMapResolve event on an ASP.NET Web page to modify the target URLs that are displayed by a site navigation control, such as the SiteMapPath control. In questo esempio, la pagina corrente è una pagina post in una bacheca online o un forum.In this example, the current page is a post page in an online bulletin board or forum. Per eseguire il rendering di una navigazione del sito più significativa, gli URL dei nodi visualizzati dal controllo di navigazione vengono accodati con stringhe di query rilevanti per il contesto.In order to render more meaningful site navigation, the URLs of the nodes that are displayed by the navigation control are appended with query strings that are relevant to the context.

Nota

È possibile accedere in modo sicuro CurrentNode alla proprietà dall'interno SiteMapResolveEventHandler della classe.It is safe to access the CurrentNode property from within the SiteMapResolveEventHandler class. L'infrastruttura di navigazione del sito di ASP.NET protegge dalla ricorsione infinita, in questo caso.The ASP.NET site navigation infrastructure guards against infinite recursion, in this case.

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

Commenti

La classe SiteMap statica espone l' SiteMapResolve evento del provider della mappa del sito predefinito.The static SiteMap class exposes the SiteMapResolve event of the default site map provider.

Quando si crea un delegato SqlDataSourceCommandEventHandler, si identifica il metodo che gestirà l'evento.When you create a SqlDataSourceCommandEventHandler delegate, you identify the method that will handle the event. Per associare l'evento al gestore eventi in uso, aggiungere all'evento un'istanza del delegato.To associate the event with your event handler, add an instance of the delegate to the event. Il gestore eventi viene chiamato ogni volta che si verifica l'evento, a meno che non venga rimosso il delegato.The event handler is called whenever the event occurs, unless you remove the delegate. Per ulteriori informazioni sui delegati del gestore eventi, vedere gestione e generazione di eventi.For more information about event handler delegates, see Handling and Raising Events.

Metodi di estensione

GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate)

Ottiene un oggetto che rappresenta il metodo rappresentato dal delegato specificato.Gets an object that represents the method represented by the specified delegate.

Si applica a

Vedi anche