Share via


SiteMap.SiteMapResolve Olay

Tanım

özelliğine CurrentNode erişildiğinde gerçekleşir.

public:
 static event System::Web::SiteMapResolveEventHandler ^ SiteMapResolve;
public static event System.Web.SiteMapResolveEventHandler SiteMapResolve;
member this.SiteMapResolve : System.Web.SiteMapResolveEventHandler 
Public Shared Custom Event SiteMapResolve As SiteMapResolveEventHandler 

Olay Türü

Örnekler

Aşağıdaki kod örneği, bir ASP.NET Web sayfasında olayın, denetim gibi SiteMapPath bir site gezinti denetimi tarafından görüntülenen hedef URL'leri değiştirmek için nasıl işleneceğini SiteMapResolve gösterir. Bu örnekte, geçerli sayfa çevrimiçi bülten panosunda veya forumda bir gönderi sayfasıdır. Daha anlamlı bir site gezintisi oluşturmak için, gezinti denetimi tarafından görüntülenen düğümlerin URL'leri bağlamla ilgili sorgu dizeleriyle eklenir.

Not

ASP.NET site gezinti altyapısı, bir koruma sağlayan ve sınıfın içinden SiteMapResolveEventHandler özelliğe erişimle ilişkili güvenlik riskini en aza indiren sonsuz yinelemeye CurrentNode karşı koruma sağlar.

Aşağıdaki kod Global.asax dosyasına aittir. Olay işleyicisi uygulama için yalnızca bir kez eklenir. Kod, sayfanın arabirimini uygulayıp uygulamadığını ISiteMapResolver tanır. Arabirim uygulanırsa ExpandForumPaths işlev çağrılır.

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

Aşağıdaki kod ayrı bir arabirim tanımlar. (Bir Web sitesi projesinde, bu kodu App_Code klasörüne koyabilirsiniz.) ISiteMapResolver arabirimi yöntemini tanımlar ExpandForumPaths .

// These methods are just placeholders for the example.
// One option is to use the HttpContext or e.Context object
// to obtain the ID.
private int GetMostRecentForumGroupID()
{
    return 24;
}

private int GetMostRecentForumID(int forumGroupId)
{
    return 128;
}

private int GetMostRecentPostID(int forumId)
{
    return 317424;
}
' These methods are just placeholders for the example.
' One option is to use the HttpContext or e.Context 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

Aşağıdaki kod, site haritası yapısının en az üç düğümü olan sayfaya aittir. Sayfa, yönteminin ISiteMapResolver çağrılmaya olanak tanıyan arabirimini ExpandForumPaths uygular.

<asp:SiteMapPath
id="SiteMapPath1"
runat="server"
RenderCurrentNodeAsLink="true" />
<asp:SiteMapPath
id="SiteMapPath1"
runat="server"
RenderCurrentNodeAsLink="true" />

Açıklamalar

Aboneler, özelliğe erişildiğinde CurrentNode bildirim almak için statik SiteMapResolve olaya bir SiteMapResolveEventHandler nesne ekler. Bu, kullanıcının özel sağlayıcı uygulaması gerektirmeden o anda yürütülen sayfanın bir SiteMapNode gösterimini oluştururken özel mantık uygulamasına olanak tanır.

Olaya aboneyseniz SiteMapResolve , varsayılan site haritası sağlayıcısında olaya da abone olursunuz SiteMapResolve .

Şunlara uygulanır

Ayrıca bkz.