SiteMapNode.Clone 方法

定义

创建作为当前节点副本的新节点。

重载

名称 说明
Clone()

创建作为当前节点副本的新节点。

Clone(Boolean)

创建一个新副本,该副本是当前节点的副本,可以选择克隆当前节点的所有父节点和上级节点。

Clone()

创建作为当前节点副本的新节点。

public:
 virtual System::Web::SiteMapNode ^ Clone();
public virtual System.Web.SiteMapNode Clone();
abstract member Clone : unit -> System.Web.SiteMapNode
override this.Clone : unit -> System.Web.SiteMapNode
Public Overridable Function Clone () As SiteMapNode

返回

作为当前节点的副本的新节点。

注解

Clone调用参数设置为 false.. 将复制提供程序、TitleUrlDescriptionKey属性。 Roles集合Attributes将复制到新集合。 不会克隆上级节点和子节点。

另请参阅

适用于

Clone(Boolean)

创建一个新副本,该副本是当前节点的副本,可以选择克隆当前节点的所有父节点和上级节点。

public:
 virtual System::Web::SiteMapNode ^ Clone(bool cloneParentNodes);
public virtual System.Web.SiteMapNode Clone(bool cloneParentNodes);
abstract member Clone : bool -> System.Web.SiteMapNode
override this.Clone : bool -> System.Web.SiteMapNode
Public Overridable Function Clone (cloneParentNodes As Boolean) As SiteMapNode

参数

cloneParentNodes
Boolean

true 克隆当前节点的所有父节点和上级节点;否则,为 false.

返回

作为当前节点的副本的新节点。

示例

下面的代码示例演示如何调用 Clone 该方法以从当前节点创建重复的站点地图节点。 该方法 ExpandForumPaths 已注册以处理 SiteMapResolve 事件。 它使用 Clone 该方法创建当前站点地图节点的工作副本,修改基于个性化设置数据的属性,并返回工作副本。

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

注解

cloneParentNodes如果参数为true,该方法Clone以递归方式克隆所有直接上级节点,并将其与当前克隆的节点相关联。 未克隆子节点。

RolesAttributes集合将应用于新集合。

另请参阅

适用于