StaticSiteMapProvider.BuildSiteMap Methode

Definition

Lädt beim Überschreiben in einer abgeleiteten Klasse die Siteübersichtsinformationen aus dem permanenten Speicher und erstellt sie im Arbeitsspeicher.When overridden in a derived class, loads the site map information from persistent storage and builds it in memory.

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

Gibt zurück

Der Stamm-SiteMapNode der Navigationsstruktur für die Siteübersicht.The root SiteMapNode of the site map navigation structure.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die BuildSiteMap -Methode zum Abrufen von Daten aus einer Microsoft Access- SiteMapNode Datenbank und zum Erstellen von Objekten ChildNodes implementiert wird, die der-Auflistung des root Site Map-Knotens hinzugefügt werden.The following code example demonstrates how to implement the BuildSiteMap method to retrieve data from a Microsoft Access database and build SiteMapNode objects that are added to the ChildNodes collection of the root site map node. Zum Schluss wird RootNode die-Eigenschaft an den Aufrufer zurückgegeben.Finally, the RootNode property is returned to the caller.

Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die StaticSiteMapProvider -Klasse bereitgestellt wird.This code example is part of a larger example provided for the StaticSiteMapProvider class.

// 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

Hinweise

Die BuildSiteMap -Methode ist der einzige abstrakte Member StaticSiteMapProvider der-Klasse.The BuildSiteMap method is the one abstract member of the StaticSiteMapProvider class. Die BuildSiteMap -Methode wird aufgerufen, um den Site Übersichts Knoten aus dem permanenten Speicher zu laden und zu erstellen.The BuildSiteMap method is called to load and build the site map node from persistent storage. Wenn Sie die BuildSiteMap -Methode implementieren, stellen Sie sicher, dass Sie Thread sicher ist, da mehrere gleichzeitige Seiten Anforderungen indirekt zu mehreren Aufrufen zum Laden von Site Übersichts Informationen führen können.When you implement the BuildSiteMap method, ensure that it is thread-safe, because multiple concurrent page requests can result indirectly in multiple calls to load site map information.

Hinweise für Vererber

Wenn Sie die BuildSiteMap() Methode in einer abgeleiteten Klasse überschreiben, müssen Sie sicherstellen, SiteMapNode dass die URLs von Objekten normalisiert werden, die Sie Ihrem Site FindSiteMapNode(String) Übersichts Anbieter hinzufügen, damit die Methode einen Site Übersichts Knoten abrufen kann, unabhängig davon, ob die URL für die Site Map der Knoten wird als absoluter virtueller Pfad oder Anwendungs relativer Pfad bereitgestellt.When overriding the BuildSiteMap() method in a derived class, be sure to normalize the URLs of SiteMapNode objects that you add to your site map provider, so that the FindSiteMapNode(String) method can retrieve a site map node regardless of whether the URL for the site map node is supplied as an absolute virtual path or application relative path. Die Implementierer von Site Map AddNode -Anbietern, die die-Methode verwenden SiteMapNode , sollten alle URLs normalisieren, bevor Objekte in den internen Hash Tabellen im Namen des Site Übersichts Anbieters gespeichert werden.Site map provider implementers using the AddNode method should normalize any URLs before storing SiteMapNode objects in the internal hash tables on behalf of the site map provider.

Das sicherheitseinschränkungs Verhalten ist in SiteMapProvider den StaticSiteMapProvider -und-Klassen Implementierungen enthalten.Security trimming behavior is included in the SiteMapProvider and StaticSiteMapProvider class implementations. Damit die Sicherheits Kürzung in abgeleiteten Klassen funktioniert, müssen Sie jedoch die Roles -Eigenschaft SiteMapNode aller Objekte festlegen, die Sie während der Erstellung eines Site Übersichts Anbieters erstellen, wenn BuildSiteMap() Sie die-Methode überschreiben.However, for security trimming to function in derived classes, you must set the Roles property of any SiteMapNode objects that you create while building a site map provider when you override the BuildSiteMap() method.

Gilt für:

Siehe auch