SiteMapNode.Clone 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建作为当前节点副本的新节点。
重载
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
的方法。 复制提供程序、 Title、 Url、 Description和 Key 属性。 和 RolesAttributes 集合将复制到新集合。 不会克隆上级节点和子节点。
另请参阅
适用于
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 方法以递归方式克隆所有直接上级节点,并将其与当前克隆的节点相关联。 不会克隆子节点。
Roles和 Attributes 集合将应用于新集合。