SiteMapResolveEventHandler 委托

定义

表示的方法将用于处理 SiteMapResolve 或静态 SiteMapProvider 类的特定实例的 SiteMap 事件。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 

参数

sender
Object

事件的源,是 SiteMapProvider 类的实例。The source of the event, an instance of the SiteMapProvider class.

e
SiteMapResolveEventArgs

包含事件数据的 SiteMapResolveEventArgsA SiteMapResolveEventArgs that contains the event data.

返回值

SiteMapNode

SiteMapNode,它表示 SiteMapResolveEventHandler 操作的结果。The SiteMapNode that represents the result of the SiteMapResolveEventHandler operation.

继承
SiteMapResolveEventHandler

示例

下面的代码示例演示如何在 ASP.NET 网页SiteMapResolve上处理事件, 以修改站点导航控件 (如SiteMapPath控件) 显示的目标 url。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. 在此示例中, 当前页面是联机公告板或论坛中的 post 页面。In this example, the current page is a post page in an online bulletin board or forum. 为了呈现更有意义的站点导航, 导航控件显示的节点 Url 附加了与上下文相关的查询字符串。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.

备注

CurrentNodeSiteMapResolveEventHandler中访问属性是安全的。It is safe to access the CurrentNode property from within the SiteMapResolveEventHandler class. 在这种情况下, ASP.NET 站点导航基础结构会阻止无限递归。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

注解

SiteMap 静态类SiteMapResolve公开默认站点地图提供程序的事件。The static SiteMap class exposes the SiteMapResolve event of the default site map provider.

创建 SqlDataSourceCommandEventHandler 委托时,需要标识将处理该事件的方法。When you create a SqlDataSourceCommandEventHandler delegate, you identify the method that will handle the event. 若要将事件与事件处理程序关联,请将该委托的一个实例添加到事件中。To associate the event with your event handler, add an instance of the delegate to the event. 除非移除了该委托,否则每当发生该事件时就会调用事件处理程序。The event handler is called whenever the event occurs, unless you remove the delegate. 有关事件处理程序委托的详细信息, 请参阅处理和引发事件For more information about event handler delegates, see Handling and Raising Events.

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。Gets an object that represents the method represented by the specified delegate.

适用于

另请参阅