SiteMapResolveEventArgs 类

定义

为通过调用 CurrentNode 类的 SiteMapProvider 属性引发的事件提供数据。Provides data for an event that is raised by calling the CurrentNode property of the SiteMapProvider class.

public ref class SiteMapResolveEventArgs : EventArgs
public class SiteMapResolveEventArgs : EventArgs
type SiteMapResolveEventArgs = class
    inherit EventArgs
Public Class SiteMapResolveEventArgs
Inherits EventArgs
继承
SiteMapResolveEventArgs

示例

下面的代码示例演示如何在 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 附加了与上下文相关的查询字符串。To render more meaningful site navigation, the URLs of the nodes displayed by the navigation control are appended with query strings that are relevant to the context.

注意CurrentNodeSiteMapResolveEventHandler中访问属性是安全的。Note 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

注解

在方法中SiteMapNode使用SiteMapResolve类来启用事件的订阅服务器, 以返回类的实例。 SiteMapResolveEventArgs ResolveSiteMapNodeThe SiteMapResolveEventArgs class is used in the ResolveSiteMapNode method to enable subscribers to the SiteMapResolve event to return an instance of the SiteMapNode class. 通过添加事件处理程序委托来处理SiteMapResolve事件, 可以SiteMapNode创建页面表示形式, 而无需实现自定义站点地图提供程序。By adding an event handler delegate to handle the SiteMapResolve event, you can create a SiteMapNode representation of a page without implementing a custom site map provider.

构造函数

SiteMapResolveEventArgs(HttpContext, SiteMapProvider)

使用指定的 HttpContextSiteMapProvider 对象初始化 SiteMapResolveEventArgs 类的新实例。Initializes a new instance of the SiteMapResolveEventArgs class using the specified HttpContext and SiteMapProvider objects.

属性

Context

获取被请求的节点所表示的页请求的上下文。Gets the context of the page request that the requested node represents.

Provider

获取引发 SiteMapProvider 事件的 SiteMapResolve 对象。Gets the SiteMapProvider object that raised the SiteMapResolve event.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅