SiteMapProvider.Initialize メソッド
アセンブリ: System.Web (system.web.dll 内)

Public Overrides Sub Initialize ( _ name As String, _ attributes As NameValueCollection _ )
Dim instance As SiteMapProvider Dim name As String Dim attributes As NameValueCollection instance.Initialize(name, attributes)
public override void Initialize ( string name, NameValueCollection attributes )
public: virtual void Initialize ( String^ name, NameValueCollection^ attributes ) override
public void Initialize ( String name, NameValueCollection attributes )
public override function Initialize ( name : String, attributes : NameValueCollection )

Initialize メソッドは、実際のサイト マップ構築は行わず、構築するための SiteMapProvider オブジェクトの状態を準備するだけです。既定の実装は、サイト マップ プロバイダの SecurityTrimmingEnabled プロパティをサイト ナビゲーション構成に基づいて初期化します。
SiteMapProvider の派生クラスは、Initialize メソッドをオーバーライドして、サイト マップ データを永続ストレージから読み込むために必要なすべての状態とリソースを初期化できます。たとえば、派生クラスでサイト マップ データの保存にファイルを使用する場合、ファイルの初期化はすべて Initialize メソッドで実行できます。派生クラスでリレーショナル データベースなどの別の種類のデータ ストアを使用する場合、データベース接続の初期化が実行されます。
ファイル名や接続文字列などの追加属性は、ASP.NET 構成システムによって読み取られ、Initialize メソッドに NameValueCollection パラメータを使用して渡されます。
継承時の注意 派生クラスで Initialize メソッドをオーバーライドする場合、基本クラスの Initialize メソッドを先に呼び出してから、独自の初期化を実行してください。
Initialize メソッドをオーバーライドして、Microsoft Access データベース接続を準備する方法を次のコード例に示します。
OleDbConnection オブジェクトの接続文字列は、Initialize メソッドの NameValueCollection パラメータとして渡されます。この場合、接続文字列は Web.config ファイルのプロバイダ固有のセクションに指定されています。accessSiteMapConnectionString には、サイト マップ データをホストする Microsoft Access データベースの接続文字列が指定されています。
<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>
このコード例は、SiteMapProvider クラスのトピックで取り上げているコード例の一部分です。
' 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 'Initialize
// 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. 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 void Initialize(String name, NameValueCollection attributes) throws Exception { if (get_IsInitialized()) { return; } super.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.get_Item( accessConnectionStringName); if (null == connectionString || connectionString.get_Length() == 0) { throw new Exception("The connection string was not found."); } else { accessConnection = new OleDbConnection(connectionString); } initialized = true; } //Initialize

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からSiteMapProvider.Initialize メソッドを検索する場合は、下記のリンクをクリックしてください。

- SiteMapProvider.Initialize メソッドのページへのリンク