閱讀英文

共用方式為


SiteMapResolveEventHandler 代理人

定義

表示將會處理 SiteMapResolve 或靜態 SiteMapProvider 類別特定執行個體之 SiteMap 事件的方法。

public delegate System.Web.SiteMapNode SiteMapResolveEventHandler(object sender, SiteMapResolveEventArgs e);

參數

sender
Object

事件的來源,為 SiteMapProvider 類別的執行個體。

e
SiteMapResolveEventArgs

SiteMapResolveEventArgs,其中包含事件資料。

傳回值

SiteMapNode,表示 SiteMapResolveEventHandler 作業的結果。

範例

下列程式碼範例示範如何處理 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;
}

備註

靜態 SiteMap 類別會 SiteMapResolve 公開預設網站地圖提供者的事件。

建立 SqlDataSourceCommandEventHandler 委派時,必須識別處理事件的方法。 若要使事件與您的事件處理常式產生關聯,請將委派的執行個體 (Instance) 加入至事件。 除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。 如需事件處理常式委派的詳細資訊,請參閱 處理和引發事件

擴充方法

GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。

適用於

產品 版本
.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

另請參閱