StaticSiteMapProvider.BuildSiteMap 메서드

정의

파생 클래스에서 재정의되면 영구 스토리지에서 사이트 맵 정보를 로드한 후 메모리에 빌드합니다.

public:
 abstract System::Web::SiteMapNode ^ BuildSiteMap();
public abstract System.Web.SiteMapNode BuildSiteMap ();
abstract member BuildSiteMap : unit -> System.Web.SiteMapNode
Public MustOverride Function BuildSiteMap () As SiteMapNode

반환

SiteMapNode

사이트 맵 탐색 구조의 루트 SiteMapNode입니다.

예제

다음 코드 예제를 구현 하는 방법에 설명 합니다 BuildSiteMap Microsoft Access 데이터베이스에서 데이터를 검색 하 여 구축 하는 메서드 SiteMapNode 에 추가 되는 개체는 ChildNodes 루트 사이트 맵 노드의 컬렉션. 마지막으로 RootNode 속성은 호출자에 게 반환 됩니다.

이 코드 예제는에 대해 제공 된 큰 예제의 일부는 StaticSiteMapProvider 클래스입니다.

// Build an in-memory representation from persistent
// storage, and return the root node of the site map.
virtual SiteMapNode ^ BuildSiteMap() override
{
   // Since the SiteMap class is static, make sure that it is
   // not modified while the site map is built.
   System::Threading::Monitor::Enter( this );
   try
   {
      
      // If there is no initialization, this method is being
      // called out of order.
      if (  !IsInitialized )
      {
         throw gcnew Exception( "BuildSiteMap called incorrectly." );
      }
      
      // If there is no root node, then there is no site map.
      if ( nullptr == rootNode )
      {
         
         // Start with a clean slate
         Clear();
         
         // Select the root node of the site map from Microsoft Access.
         int rootNodeId = -1;
         if ( accessConnection->State == ConnectionState::Closed )
            accessConnection->Open();
         
         OleDbCommand^ rootNodeCommand = gcnew OleDbCommand
            ("SELECT nodeid, url, name FROM SiteMap WHERE parentnodeid IS NULL", accessConnection);
         OleDbDataReader^ rootNodeReader = rootNodeCommand->ExecuteReader();
         if ( rootNodeReader->HasRows )
         {
            rootNodeReader->Read();
            rootNodeId = rootNodeReader->GetInt32( 0 );
            
            // Create a SiteMapNode that references the current StaticSiteMapProvider.
            rootNode = gcnew SiteMapNode(this, rootNodeId.ToString(), 
               rootNodeReader->GetString( 1 ),rootNodeReader->GetString( 2 ));
         }
         else
            return nullptr;
         rootNodeReader->Close();
         
         // Select the child nodes of the root node.
         OleDbCommand^ childNodesCommand = gcnew OleDbCommand
            ("SELECT nodeid, url, name FROM SiteMap WHERE parentnodeid = ?", accessConnection);
         OleDbParameter^ rootParam = gcnew OleDbParameter( "parentid", OleDbType::Integer);
         rootParam->Value = rootNodeId;
         childNodesCommand->Parameters->Add( rootParam );
         OleDbDataReader^ childNodesReader = childNodesCommand->ExecuteReader();
         if ( childNodesReader->HasRows )
         {
            SiteMapNode ^ childNode = nullptr;
            while ( childNodesReader->Read() )
            {
               childNode = gcnew SiteMapNode( this, 
                   System::Convert::ToString(childNodesReader->GetInt32( 0 )),
                  childNodesReader->GetString( 1 ),
                  childNodesReader->GetString( 2 ) 
               );
               // Use the SiteMapNode AddNode method to add
               // the SiteMapNode to the ChildNodes collection.
               AddNode( childNode, rootNode );
            }
         }
         childNodesReader->Close();
         accessConnection->Close();
      }
      return rootNode;
   }
   finally
   {
      System::Threading::Monitor::Exit( this );
   }

}
// Build an in-memory representation from persistent
// storage, and return the root node of the site map.
public override SiteMapNode BuildSiteMap() {

    // Since the SiteMap class is static, make sure that it is
    // not modified while the site map is built.
    lock(this) {

        // If there is no initialization, this method is being
        // called out of order.
        if (! IsInitialized) {
            throw new Exception("BuildSiteMap called incorrectly.");
        }

        // If there is no root node, then there is no site map.
        if (null == rootNode) {
            // Start with a clean slate
            Clear();

            // Select the root node of the site map from Microsoft Access.
            int rootNodeId = -1;

            if (accessConnection.State == ConnectionState.Closed)
                accessConnection.Open();
            OleDbCommand rootNodeCommand =
                new OleDbCommand("SELECT nodeid, url, name FROM SiteMap WHERE parentnodeid IS NULL",
                                 accessConnection);
            OleDbDataReader rootNodeReader = rootNodeCommand.ExecuteReader();

            if(rootNodeReader.HasRows) {
                rootNodeReader.Read();
                rootNodeId = rootNodeReader.GetInt32(0);
                // Create a SiteMapNode that references the current StaticSiteMapProvider.
                rootNode   = new SiteMapNode(this,
                                             rootNodeId.ToString(),
                                             rootNodeReader.GetString(1),
                                             rootNodeReader.GetString(2));
            }
            else
            {
                return null;
            }

            rootNodeReader.Close();
            // Select the child nodes of the root node.
            OleDbCommand childNodesCommand =
                new OleDbCommand("SELECT nodeid, url, name FROM SiteMap WHERE parentnodeid = ?",
                                 accessConnection);
            OleDbParameter rootParam = new OleDbParameter("parentid", OleDbType.Integer);
            rootParam.Value = rootNodeId;
            childNodesCommand.Parameters.Add(rootParam);

            OleDbDataReader childNodesReader = childNodesCommand.ExecuteReader();

            if (childNodesReader.HasRows) {

                SiteMapNode childNode = null;
                while(childNodesReader.Read()) {
                    childNode =  new SiteMapNode(this,
                                                 childNodesReader.GetInt32(0).ToString(),
                                                 childNodesReader.GetString(1),
                                                 childNodesReader.GetString(2));

                    // Use the SiteMapNode AddNode method to add
                    // the SiteMapNode to the ChildNodes collection.
                    AddNode(childNode, rootNode);
                }
            }

            childNodesReader.Close();
            accessConnection.Close();
        }
        return rootNode;
    }
}
' Build an in-memory representation from persistent
' storage, and return the root node of the site map.
Public Overrides Function BuildSiteMap() As SiteMapNode

    ' Since the SiteMap class is static, make sure that it is
    ' not modified while the site map is built.
    SyncLock Me

        ' If there is no initialization, this method is being
        ' called out of order.
        If Not IsInitialized Then
            Throw New Exception("BuildSiteMap called incorrectly.")
        End If

        ' If there is no root node, then there is no site map.
        If aRootNode Is Nothing Then
            ' Start with a clean slate
            Clear()

            ' Select the root node of the site map from Microsoft Access.
            Dim rootNodeId As Integer = -1

            If accessConnection.State = ConnectionState.Closed Then
                accessConnection.Open()
            End If
            Dim rootNodeCommand As New OleDbCommand("SELECT nodeid, url, name FROM SiteMap WHERE parentnodeid IS NULL", accessConnection)
            Dim rootNodeReader As OleDbDataReader = rootNodeCommand.ExecuteReader()

            If rootNodeReader.HasRows Then
                rootNodeReader.Read()
                rootNodeId = rootNodeReader.GetInt32(0)
                ' Create a SiteMapNode that references the current StaticSiteMapProvider.
                aRootNode = New SiteMapNode(Me, rootNodeId.ToString(), rootNodeReader.GetString(1), rootNodeReader.GetString(2))
            Else
                Return Nothing
            End If
            rootNodeReader.Close()
            ' Select the child nodes of the root node.
            Dim childNodesCommand As New OleDbCommand("SELECT nodeid, url, name FROM SiteMap WHERE parentnodeid = ?", accessConnection)
            Dim rootParam As New OleDbParameter("parentid", OleDbType.Integer)
            rootParam.Value = rootNodeId
            childNodesCommand.Parameters.Add(rootParam)

            Dim childNodesReader As OleDbDataReader = childNodesCommand.ExecuteReader()

            If childNodesReader.HasRows Then

                Dim childNode As SiteMapNode = Nothing
                While childNodesReader.Read()
                    childNode = New SiteMapNode(Me, _
                    childNodesReader.GetInt32(0).ToString(), _
                    childNodesReader.GetString(1), _
                    childNodesReader.GetString(2))

                    ' Use the SiteMapNode AddNode method to add
                    ' the SiteMapNode to the ChildNodes collection.
                    AddNode(childNode, aRootNode)
                End While
            End If

            childNodesReader.Close()
            accessConnection.Close()
        End If
        Return aRootNode
    End SyncLock

End Function 'BuildSiteMap

설명

BuildSiteMap 메서드는의 추상 멤버는 StaticSiteMapProvider 클래스입니다. 영구 스토리지에서 사이트 맵 노드를 로드하고 빌드하기 위해 BuildSiteMap 메서드가 호출됩니다. 구현 하는 경우는 BuildSiteMap 메서드를 여러 동시 페이지 요청 사이트 맵 정보를 로드 하는 여러 호출에서 직접 발생할 수 있으므로 스레드로부터 안전 인지 확인 합니다.

구현자 참고

재정의 하는 경우는 BuildSiteMap() 파생된 클래스에서 메서드를의 Url을 정규화 해야 SiteMapNode 사이트 맵 공급자를 추가 하는 개체 있도록는 FindSiteMapNode(String) 여부에 관계 없이 사이트 맵 노드를 검색할 수 사이트 맵에 대 한 URL 노드 가상 절대 경로 또는 상대 경로 애플리케이션으로 제공 됩니다. 사용 하 여 사이트 맵 공급자 구현자는 AddNode 메서드를 저장 하기 전에 모든 Url을 정규화 해야 SiteMapNode 사이트 맵 공급자를 대신 하 여 내부 해시 테이블에 있는 개체입니다.

보안 조정 동작에 포함 되어는 SiteMapProviderStaticSiteMapProvider 클래스 구현 합니다. 그러나 파생된 클래스에서 함수를 보안 트리밍이 설정 해야 합니다는 Roles 속성을 SiteMapNode 재정의 하는 경우 사이트 맵 공급자를 빌드하는 동안 만든 개체는 BuildSiteMap() 메서드.

적용 대상

추가 정보