SiteMap.SiteMapResolve 이벤트

정의

CurrentNode 속성에 액세스할 때 발생합니다.

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 

이벤트 유형

예제

다음 코드 예제에서는 처리 하는 방법에 설명 합니다 SiteMapResolve 이벤트와 같은 사이트 탐색 컨트롤에 의해 표시 되는 대상 Url을 수정 하는 ASP.NET 웹 페이지에는 SiteMapPath 컨트롤입니다. 이 예제에서는 현재 페이지의 온라인 게시판 또는 포럼 게시물 페이지입니다. 보다 의미 있는 렌더링 하기 위해 사이트 탐색, 탐색 컨트롤에 의해 표시 되는 노드의 Url은 상황에 맞는 관련 쿼리 문자열이 포함 된 추가 됩니다.

참고

ASP.NET 사이트 탐색 인프라 액세스와 연결 된 보안 위험을 최소화 하 고 보호할 수 있는 무한 재귀가 발생 하지 않도록 합니다 CurrentNode 내에서 속성을 SiteMapResolveEventHandler 클래스.

다음 코드를 Global.asax 파일에 속해 있습니다. 이벤트 처리기는 애플리케이션에 대 한 한 번만 연결 됩니다. 코드 페이지를 구현 하는지 여부를 인식 합니다 ISiteMapResolver 인터페이스입니다. 인터페이스를 구현 하는 경우는 ExpandForumPaths 함수를 호출 합니다.

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

다음 코드는 별도 인터페이스를 정의 합니다. (웹 사이트 프로젝트에 넣을 수 있습니다이 코드를 App_Code 폴더에.) 합니다 ISiteMapResolver 인터페이스를 정의 합니다 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

다음 코드를 최소한 3 개의 노드가 있는 페이지를 사용 하 여 속한 사이트 맵 구조의 깊이입니다. 페이지를 구현 하는 ISiteMapResolver 인터페이스를 ExpandForumPaths 호출 될 메서드입니다.

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

설명

구독자 연결을 SiteMapResolveEventHandler 개체를 정적 SiteMapResolve 이벤트 알림을 받을 때는 CurrentNode 속성에 액세스. 이렇게 하면 사용자를 만들 때 사용자 지정 논리를 구현 하는 SiteMapNode 는 사용자 지정 공급자 구현으로 요구 하지 않고 현재 실행 중인 페이지의 표현입니다.

구독 하는 경우는 SiteMapResolve 이벤트를 구독할 수도 SiteMapResolve 기본 사이트 맵 공급자에는 이벤트입니다.

적용 대상

추가 정보