SiteMapResolveEventArgs 类

定义

为通过调用 CurrentNode 类的 SiteMapProvider 属性引发的事件提供数据。

C#
public class SiteMapResolveEventArgs : EventArgs
继承
SiteMapResolveEventArgs

示例

下面的代码示例演示如何处理 SiteMapResolve ASP.NET 网页上的事件,以修改网站导航控件(如 SiteMapPath 控件)显示的目标 URL。 在此示例中,当前页面是在线公告板或论坛中的帖子页。 为了呈现更有意义的网站导航,导航控件显示的节点的 URL 会追加与上下文相关的查询字符串。

注意从 类内部SiteMapResolveEventHandler访问 CurrentNode 属性是安全的。 在本例中,ASP.NET 站点导航基础结构可防止无限递归。

C#
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;
}

注解

SiteMapResolveEventArgs 方法中使用 ResolveSiteMapNode 类,使事件的订阅者 SiteMapResolve 能够返回 类的 SiteMapNode 实例。 通过添加事件处理程序委托来处理事件 SiteMapResolve ,可以创建 SiteMapNode 页面的表示形式,而无需实现自定义站点地图提供程序。

构造函数

属性

Context

获取被请求的节点所表示的页请求的上下文。

Provider

获取引发 SiteMapProvider 事件的 SiteMapResolve 对象。

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

另请参阅