This documentation is archived and is not being maintained.

SiteMapProvider.Initialize Method

Initializes the SiteMapProvider implementation, including any resources that are needed to load site map data from persistent storage.

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)

public override void Initialize(
	string name,
	NameValueCollection attributes


Type: System.String

The Name of the provider to initialize.

Type: System.Collections.Specialized.NameValueCollection

A NameValueCollection that can contain additional attributes to help initialize the provider. These attributes are read from the site map provider configuration in the Web.config file.

The Initialize method does not actually build a site map, it only prepares the state of the SiteMapProvider object to do so. The default implementation initializes the SecurityTrimmingEnabled property for the site map provider from the site navigation configuration.

Classes that derive from the SiteMapProvider can override the Initialize method to initialize any state and resources that are required to load site map data from persistent storage. For example, if your derived class is using files to store site map data, any file initialization can be performed in the Initialize method. If the derived class uses some other type of data store, such as a relational database, initializing a database connection might be performed.

Additional attributes, such as file names or connection strings, are read by the ASP.NET configuration system and passed to the Initialize method with its NameValueCollection parameter.

Notes to Inheritors:

When overriding the Initialize method in a derived class, be sure to first call the Initialize method for the base class before performing your own initializations.

The following code example demonstrates how to override the Initialize method to prepare a Microsoft Access database connection.

The connection string for the OleDbConnection object is passed in the NameValueCollection parameter of the Initialize method. In this case, the connection string is provided by the provider-specific section in the Web.config file. Here, accessSiteMapConnectionString contains a connection string to a Microsoft Access database that hosts the site map data.

<siteMap defaultProvider="AccessSiteMapProvider">
       accessSiteMapConnectionString="PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=\\SomeUNCShare\\sitemap.mdb"/>

This code example is part of a larger example provided for the SiteMapProvider class.

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

    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.");
        accessConnection = new OleDbConnection(connectionString);

    initialized = true;

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0