StaticSiteMapProvider.BuildSiteMap メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > StaticSiteMapProvider.BuildSiteMap メソッドの意味・解説 

StaticSiteMapProvider.BuildSiteMap メソッド

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

派生クラスでオーバーライドされた場合は、サイト マップ情報を永続ストレージから読み込み、メモリ内で構築します。

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public MustOverride Function
 BuildSiteMap As SiteMapNode
Dim instance As StaticSiteMapProvider
Dim returnValue As SiteMapNode

returnValue = instance.BuildSiteMap
public abstract SiteMapNode BuildSiteMap ()
public:
virtual SiteMapNode^ BuildSiteMap () abstract
public abstract SiteMapNode BuildSiteMap ()
public abstract function BuildSiteMap () :
 SiteMapNode

戻り値
サイト マップ ナビゲーション構造のルート SiteMapNode。

解説解説

BuildSiteMap メソッドは、StaticSiteMapProvider クラスの唯一の抽象メンバです。BuildSiteMap メソッドは、サイト マップ ノードを永続ストレージから読み込んで構築するために呼び出されます。ページが同時に複数要求されると、サイト マップ情報の読み込みが間接的に複数呼び出されることになるため、BuildSiteMap メソッドを実装する場合は、スレッド セーフであることを確認してください。

継承時の注意 BuildSiteMap メソッドをオーバーライドする場合、サイト マップ プロバイダに追加する SiteMapNode オブジェクトの URL を正規化してください。これによって、サイト マップ ノードの URL の指定が絶対仮想パスでもアプリケーション相対パスでも、FindSiteMapNode メソッドがサイト マップ ノードを取得できます。AddNode メソッドを使用するサイト マップ プロバイダの実装側は、サイト マップ プロバイダの代わりに、URL をすべて正規化してから、SiteMapNode オブジェクトを内部ハッシュ テーブルに格納する必要があります。 セキュリティ トリミング動作は、SiteMapProvider クラスと StaticSiteMapProvider クラスの実装に用意されています。ただし、BuildSiteMap メソッドをオーバーライドする場合は、セキュリティ トリミングが派生クラスでも動作するよう、サイト マップ プロバイダの構築時に作成するすべての SiteMapNode オブジェクトについて、Roles プロパティを設定する必要があります。

メモ重要 :

BuildSiteMap メソッドは、FindSiteMapNode、GetChildNodes、および GetParentNode の各メソッドの既定の実装によって呼び出されます。BuildSiteMap メソッドを派生クラスでオーバーライドする場合、サイト マップ データの読み込みを 1 度に限定し、それ以降の呼び出しでは制御がすぐに戻るようにしてください。

使用例使用例

BuildSiteMap メソッドを実装して Microsoft Access データベースからデータを取得し、ルート サイト マップ ノードの ChildNodes コレクションに追加される SiteMapNode オブジェクトを構築する方法を次のコード例に示します。最後に、RootNode プロパティが呼び出し元に返されます。

このコード例は、StaticSiteMapProvider クラスのトピックで取り上げているコード例の一部分です。

' 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
// 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.
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 SiteMapNode BuildSiteMap() throws Exception
{
    // Since the SiteMap class is static, make sure that it is
    // not modified while the site map is built.
    synchronized (this)
    {
        // If there is no initialization, this method is being
        // called out of order.
        if (!get_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.get_State().Equals(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.get_HasRows())
            {
                rootNodeReader.Read();
                rootNodeId = rootNodeReader.GetInt32(0);
                // Create a SiteMapNode that references the current
 
                // StaticSiteMapProvider.
                rootNode = new SiteMapNode(this
,
                    ((Int32)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.set_Value((Int32)rootNodeId);
            childNodesCommand.get_Parameters().Add(rootParam);

            OleDbDataReader childNodesReader = childNodesCommand.
                ExecuteReader();

            if (childNodesReader.get_HasRows())
            {
                SiteMapNode childNode = null;
                while (childNodesReader.Read())
                {
                    childNode = new SiteMapNode(this
,
                        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;
    }
} //BuildSiteMap

protected SiteMapNode GetRootNodeCore()
{
    return null;
} //GetRootNodeCore
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
StaticSiteMapProvider クラス
StaticSiteMapProvider メンバ
System.Web 名前空間
SiteMapProvider.RootNode プロパティ
Initialize
Clear



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

StaticSiteMapProvider.BuildSiteMap メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



StaticSiteMapProvider.BuildSiteMap メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS