How to: Implement ASP.NET Site-Map Providers

This topic describes how you can build ASP.NET site-map providers and configure an ASP.NET application to use a site-map provider.

The following table lists the accompanying topics, which include the code for two example site-map providers written in Visual Basic and C#. One of the example providers uses the .NET Framework Data Provider for ODBC to connect to an ODBC data source. The other example uses a Microsoft Access database as its data source.

Example Text Site-Map Provider

Illustrates a complete text-based site-map provider.

Example Access Site-Map Provider

Illustrates a complete Access-based site-map provider.

To build a site-map provider

  • Place your source code in the App_Code directory of your application.


    If you already have source code in the App_Code directory of your application, you must add the version of the site-map provider that is written in the same language as the existing code in the directory.

    The provider will be compiled by ASP.NET when your application is requested. For more information, see Shared Code Folders in ASP.NET Web Sites.


    Alternatively, compile the site-map provider as a library and place it in the Bin directory of your Web application, or strongly name it and place it in the global assembly cache (GAC). For example, the following command shows how you can compile an example site-map provider using the command-line compiler.

    vbc /out:<example_name>.dll /t:library <example_name>.vb /r:System.Web.dll /r:System.Configuration.dll

    csc /out:<example_name>.dll /t:library <example_name>.cs /r:System.Web.dll /r:System.Configuration.dll

To use the site-map provider in an ASP.NET application

  1. Configure your Web application to use the site-map provider, adding the provider to your Web.config file.

  2. Add controls that use the site-map provider. After the Web.config file is altered and the provider is compiled, the provider loads navigation data into the instance of the SiteMap class that is in memory. Now the navigation data can be used by components of the site-map infrastructure — such as the SiteMapPath, TreeView, and Menu controls — to display site-map information for users. The following example code uses all three of these controls in an ASP.NET page.

    <%@ Page Language="C#" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <script runat="server">
    <html xmlns="" >
    <head runat="server">
      <title>Simple Navigation Controls</title>
      <form id="form1" runat="server">
      <h2>Using SiteMapPath</h2>
      <asp:SiteMapPath ID="SiteMapPath1" Runat="server">
      <asp:SiteMapDataSource ID="SiteMapDataSource1" Runat="server" />
      <h2>Using TreeView</h2>
      <asp:TreeView ID="TreeView1" Runat="Server" DataSourceID="SiteMapDataSource1">
      <h2>Using Menu</h2>
      <asp:Menu ID="Menu2" Runat="server" DataSourceID="SiteMapDataSource1">
      <h2>Using a Horizontal Menu</h2>
      <asp:Menu ID="Menu1" Runat="server" DataSourceID="SiteMapDataSource1"
        StaticDisplayLevels="2" >

See Also