SiteMap.SiteMapResolve Ereignis

Definition

Tritt ein, wenn auf die CurrentNode-Eigenschaft zugegriffen wird.Occurs when the CurrentNode property is accessed.

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 

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie das SiteMapResolve -Ereignis auf einer ASP.NET-Webseite behandelt wird, um die Ziel-URLs zu ändern, die von einem site Navigations SiteMapPath Steuerelement wie dem-Steuerelement angezeigt werden.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 diesem Beispiel ist die aktuelle Seite eine Post-Seite in einem Online Bulletin Board oder-Forum.In this example, the current page is a post page in an online bulletin board or forum. Um eine aussagekräftigere Website Navigation zu erzeugen, werden die URLs der Knoten, die vom Navigations Steuerelement angezeigt werden, mit Kontext relevanten Abfrage Zeichenfolgen angehängt.In order to render more meaningful site navigation, the URLs of the nodes that are displayed by the navigation control are appended with context relevant query strings.

Hinweis

Die ASP.net-Site Navigations Infrastruktur schützt vor unbegrenzter Rekursion, die eine Schutzvorrichtung bietet und das Sicherheitsrisiko minimiert, das CurrentNode dem Zugriff auf die SiteMapResolveEventHandler -Eigenschaft innerhalb der-Klasse zugeordnet ist.The ASP.NET site navigation infrastructure guards against infinite recursion, which provides a safeguard and minimizes the security risk that is associated with accessing the CurrentNode property from within the SiteMapResolveEventHandler class.

Der folgende Code gehört zur Datei Global. asax.The following code belongs in the Global.asax file. Der Ereignishandler wird nur einmal für die Anwendung angefügt.The event handler will be attached only once for the application. Der Code erkennt, ob die Seite die ISiteMapResolver -Schnittstelle implementiert.The code recognizes whether the page implements the ISiteMapResolver interface. Wenn die-Schnittstelle implementiert ist ExpandForumPaths , wird die-Funktion aufgerufen.If the interface is implemented, the ExpandForumPaths function is called.

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

Der folgende Code definiert eine separate Schnittstelle.The following code defines a separate interface. (In einem Website Projekt können Sie diesen Code in den Ordner "App_Code" einfügen.) Die ISiteMapResolver -Schnittstelle ExpandForumPaths definiert die-Methode.(In a Web site project, you can put this code in the App_Code folder.) The ISiteMapResolver interface defines the ExpandForumPaths method.

// 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

Der folgende Code gehört zu der Seite, die mindestens drei Knoten tief in der Site-Map-Struktur ist.The following code belongs with the page that is at least three nodes deep in the site-map structure. Die Seite implementiert die ISiteMapResolver -Schnittstelle, mit ExpandForumPaths der die-Methode aufgerufen werden kann.The page implements the ISiteMapResolver interface, which enables the ExpandForumPaths method to be called.

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

Hinweise

Abonnenten fügen dem SiteMapResolveEventHandler statischen SiteMapResolve Ereignis ein-Objekt hinzu, um eine Benachrichtigung CurrentNode zu erhalten, wenn auf die Eigenschaft zugegriffen wird.Subscribers attach a SiteMapResolveEventHandler object to the static SiteMapResolve event to receive notification when the CurrentNode property is accessed. Dadurch kann der Benutzer benutzerdefinierte Logik implementieren, wenn eine SiteMapNode Darstellung der aktuell ausgeführten Seite erstellt wird, ohne dass eine benutzerdefinierte Anbieter Implementierung erforderlich ist.This enables the user to implement custom logic when creating a SiteMapNode representation of the currently executing page without requiring a custom provider implementation.

Wenn Sie das SiteMapResolve -Ereignis abonnieren, abonnieren Sie auch das SiteMapResolve -Ereignis für den standardmäßigen Site Übersichts Anbieter.If you subscribe to the SiteMapResolve event, you also subscribe to the SiteMapResolve event on the default site map provider.

Gilt für:

Siehe auch