To create the Access table that is used by the previous code example as the site-map data store, issue the following data-definition query in a new or existing Access database, and then save the Access database with the file name Sitemap.mdb.
CREATE TABLE SiteMap
(
URL Text (255) UNIQUE,
NAME Text (255) NOT NULL,
PARENTNODEID Int32,
CONSTRAINT NODEID PRIMARY KEY (URL, NAME)
)
Populate the table with the following kinds of data, listing files that you have in your Web site or files that you can create. The following table shows an example file listing.
NODEID | URL | NAME | PARENTNODEID |
|---|
1 | Default.aspx | Default | null (empty cell) |
2 | Catalog.aspx | Catalog | 1 |
3 | Aboutus.aspx | Contact Us | 1 |
Note: |
|---|
Because data sources contain differing SQL syntax, some commands will work with one data source and not with another. As a result, it is recommended that you create a site-map provider that is specific to your data source, even if you are using the .NET Framework Data Provider for ODBC or the .NET Framework Data Provider for OLE DB to access your data source (for example, SybaseSiteMapProvider, OracleSiteMapProvider, and so on). |
The AccessSiteMapProvider class derives from the StaticSiteMapProvider class, and retrieves its information from an Access database using basic SQL queries as well as OleDbCommand and OleDbDataReader objects.
Finally, AccessSiteMapProvider is configured to be the default provider in the Web.config file, as shown in the following code example.
<configuration>
<system.web>
<siteMap defaultProvider="AccessSiteMapProvider">
<providers>
<add
name="AccessSiteMapProvider"
type="<type name>"
accessSiteMapConnectionString="PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=<path>\sitemap.mdb "/>
</providers>
</siteMap>
</system.web>
</configuration>
To customize this example, replace <type name> with the fully qualified name of the class that implements your site-map data provider. For example, in the C# code above, you would replace <type name> with Samples.AspNet.CS.Controls.AccessSiteMapProvider. If you compile your site-map data provider code and place it in the Bin directory, the <type name> string must also include the name of your compiled file without the file name extension. For example, if you compiled the C# code above into a file called Samples.AspNet.dll, you would replace <type name> with Samples.AspNet.CS.Controls.AccessSiteMapProvider.Samples.AspNet. Lastly, replace <path> with the absolute physical path to your site-map database.