共用方式為


SiteMapResolveEventArgs 類別

定義

針對呼叫 CurrentNode 類別的 SiteMapProvider 屬性所引發的事件,提供相關資料。

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

範例

下列程式碼範例示範如何處理 SiteMapResolve ASP.NET 網頁上的事件,以修改網站導覽控制項所顯示的目標 URL,例如 SiteMapPath 控制項。 在此範例中,目前頁面是線上佈告欄或論壇中的文章頁面。 為了轉譯更有意義的網站導覽,導覽控制項所顯示之節點的 URL 會附加與內容相關的查詢字串。

注意從 類別內 SiteMapResolveEventHandler 存取 CurrentNode 屬性是安全的。 在此案例中,ASP.NET 網站導覽基礎結構會防範無限遞迴。

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

備註

類別 SiteMapResolveEventArgs 用於 方法中 ResolveSiteMapNode ,可讓事件的訂閱者 SiteMapResolve 傳回 類別的 SiteMapNode 實例。 藉由新增事件處理常式委派來處理 SiteMapResolve 事件,您可以建立 SiteMapNode 頁面的標記法,而不需要實作自訂網站地圖提供者。

建構函式

SiteMapResolveEventArgs(HttpContext, SiteMapProvider)

使用指定的 HttpContextSiteMapProvider 物件,初始化 SiteMapResolveEventArgs 類別的新執行個體。

屬性

Context

取得所要求之節點表示的網頁要求內容。

Provider

取得引發 SiteMapProvider 事件的 SiteMapResolve 物件。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱