做網站(Web Form)常會使用網頁節點,

.net 的網頁節點可以直客使用 Web.SiteMap 來做設定,

Web.sitemap 檔可能如下所示。

<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
  <siteMapNode title="Forum Group" description="Forum Group List" url="default.aspx">
    <siteMapNode title="Forum" description="Forum List" url="ShowForum.aspx">
      <siteMapNode title="Post" description="Post List" url="ShowPost.aspx" />
    </siteMapNode>
  </siteMapNode>
</siteMap>

 

以下直接以程式方式呈現

Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    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

' These methods are just placeholders for the example.
' One option is to use the HttpContext or e.Content object
' to obtain the ID.
Private Function GetMostRecentForumGroupID() As Integer
    Return 24
End Function

Private Function GetMostRecentForumID(ByVal forumGroupId As Integer) As Integer
    Return 128
End Function

Private Function GetMostRecentPostID(ByVal forumId As Integer) As Integer
    Return 317424
End Function

 

參考 https://msdn.microsoft.com/zh-tw/library/ms178425(v=vs.100).aspx
http://goodlucky.pixnet.net/blog/post/47797029


arrow
arrow
    文章標籤
    sitemap 相同url siteMapNode
    全站熱搜

    Roger 發表在 痞客邦 留言(0) 人氣()