SiteMapProvider.Initialize(String, NameValueCollection) Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Initierar implementeringen SiteMapProvider , inklusive alla resurser som behövs för att läsa in webbplatsöversiktsdata från beständig lagring.
public:
override void Initialize(System::String ^ name, System::Collections::Specialized::NameValueCollection ^ attributes);
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection attributes);
override this.Initialize : string * System.Collections.Specialized.NameValueCollection -> unit
Public Overrides Sub Initialize (name As String, attributes As NameValueCollection)
Parametrar
- attributes
- NameValueCollection
En NameValueCollection som kan innehålla ytterligare attribut för att initiera providern. De här attributen läse från platskartans providerkonfiguration i Web.config-filen.
Exempel
Följande kodexempel visar hur du åsidosätter metoden Initialize för att förbereda en Microsoft Access databasanslutning.
Connection string för objektet OleDbConnection skickas i parametern NameValueCollection för metoden Initialize. I det här fallet tillhandahålls reťazec pripojenia av det providerspecifika avsnittet i Web.config-filen. Här innehåller accessSiteMapConnectionString en reťazec pripojenia till en Microsoft Access databas som är värd för platsöversiktsdata.
<siteMap defaultProvider="AccessSiteMapProvider">
<providers>
<add
name="AccessSiteMapProvider"
type="Samples.AspNet.AccessSiteMapProvider,Samples.AspNet"
accessSiteMapConnectionString="PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=\\SomeUNCShare\\sitemap.mdb"/>
</providers>
</siteMap>
Det här kodexemplet är en del av ett större exempel för SiteMapProvider klassen.
// Initialize is used to initialize the properties and any state that the
// AccessProvider holds, but is not used to build the site map.
// The site map is built when the BuildSiteMap method is called.
virtual void Initialize( String^ name, NameValueCollection^ attributes ) override
{
if ( IsInitialized )
return;
StaticSiteMapProvider::Initialize( name, attributes );
// Create and test the connection to the Microsoft Access database.
// Retrieve the Value of the Access connection string from the
// attributes NameValueCollection.
String^ connectionString = attributes[ AccessConnectionStringName ];
if ( nullptr == connectionString || connectionString->Length == 0 )
throw gcnew Exception( "The connection string was not found." );
else
accessConnection = gcnew OleDbConnection( connectionString );
initialized = true;
}
protected:
// Initialize is used to initialize the properties and any state that the
// AccessProvider holds, but is not used to build the site map.
// The site map is built when the BuildSiteMap method is called.
public override void Initialize(string name, NameValueCollection attributes) {
if (IsInitialized)
return;
base.Initialize(name, attributes);
// Create and test the connection to the Microsoft Access database.
// Retrieve the Value of the Access connection string from the
// attributes NameValueCollection.
string connectionString = attributes[AccessConnectionStringName];
if (null == connectionString || connectionString.Length == 0)
throw new Exception ("The connection string was not found.");
else
accessConnection = new OleDbConnection(connectionString);
initialized = true;
}
' Initialize is used to initialize the properties and any state that the
' AccessProvider holds, but is not used to build the site map.
' The site map is built when the BuildSiteMap method is called.
Public Overrides Sub Initialize(ByVal name As String, ByVal attributes As NameValueCollection)
If IsInitialized Then
Return
End If
MyBase.Initialize(name, attributes)
' Create and test the connection to the Microsoft Access database.
' Retrieve the Value of the Access connection string from the
' attributes NameValueCollection.
Dim connectionString As String = attributes(AccessConnectionStringName)
If Nothing = connectionString OrElse connectionString.Length = 0 Then
Throw New Exception("The connection string was not found.")
Else
accessConnection = New OleDbConnection(connectionString)
End If
initialized = True
End Sub
Kommentarer
Metoden Initialize skapar inte en webbplatskarta, utan förbereder bara objektets SiteMapProvider tillstånd för att göra det. Standardimplementeringen initierar SecurityTrimmingEnabled egenskapen för platskarteprovidern från platsnavigeringskonfigurationen.
Klasser som härleds från SiteMapProvider kan åsidosätta Initialize metoden för att initiera alla tillstånd och resurser som krävs för att läsa in platsmappningsdata från beständig lagring. Om din härledda klass till exempel använder filer för att lagra webbplatsöversiktsdata kan alla filinitieringar utföras i Initialize metoden. Om den härledda klassen använder någon annan typ av datalager, till exempel en relationsdatabas, kan initiering av en databasanslutning utföras.
Ytterligare attribut, till exempel filnamn eller anslutningssträngar, läss av ASP.NET-konfigurationssystemet och skickas till metoden Initialize med parametern NameValueCollection.
Anteckningar till arvingar
När du åsidosättar Initialize(String, NameValueCollection) metoden i en härledd klass måste du först anropa Initialize(String, NameValueCollection) metoden för basklassen innan du utför dina egna initieringar.