---
title: "Implementing ASP.NET Custom Site-Map"  
description: "In this blog I am trying to Implementing ASP.NET Custom Site-Map.A site map (or sitemap) is a list of web pages of a web site that are accessed by the"  
author: "Anonymous User"  
published: 2013-08-22  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/571/implementing-asp-dot-net-custom-site-map  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 7 minutes  

---

# Implementing ASP.NET Custom Site-Map

In this blog I am trying to Implementing ASP.NET Custom Site-Map.

A site map (or sitemap) is a list of web pages of a web site that are accessed by the users. ASP.NET site navigation provides several Web server controls that display a navigation structure on a Web page: the SiteMapPath, TreeView, and Menu controls that are.

[XML Sitemap](https://www.mindstick.com/forum/33731/tell-me-about-xml-sitemap)

An XML Sitemap is a structured format that a user doesn't need to see, but it tells the search engine about the pages in your site, their relative importance to each other, and how often (frequently) they are updated.

##### HTML Sitemap

HTML sitemaps are basically designed for the user to help them to find the content on the page, and they don't need to include each and every subpage. This is very helpful to visitors and search engine to find pages on the site.

XML is a document structure and encoding standard used, amongst many other things, as the standard for web crawlers to find and parse sitemaps. Site maps can improve [search engine optimization](https://www.mindstick.com/services/search-engine-optimization) of a site by making sure that all the pages can be found.

ASP.NET Site map

This provides default site map for navigation of web site. In ASP.NET the site navigation provides many Web server controls that can display a navigation structure on a Web page: that are SiteMapPath, TreeView, and Menu controls .These all Web server controls are used by the ASP.NET default site-map provider, or the XmlSiteMapProvider class, to access site-map information from the XML-formatted Web.sitemap file.

However you can [implement your](https://www.mindstick.com/forum/161528/implement-your-own-version-of-the-max-function-in-python) own custom site-map provider, according to your requirement. There are basically three primary reasons for which we need to create a custom site-map provider are as follows:

1. First is that if you want to store site-map information in a [data source](https://www.mindstick.com/interview/808/what-is-a-data-source), then with the default implementation of ASP.NET site-map provider it could not be stored, because it is not supported by default implementation. For example, you might want to [store your](https://www.mindstick.com/articles/44359/store-your-valuable-items-in-a-mini-storage-unit) site-map data in a Visual FoxPro database, an [Oracle database](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database), or other data source.

2. Second is to manage navigation information using a schema that is different from the schema used for the Web. Sitemap file. For example, you might have an existing implementation for storing site-map data.

3. To use a dynamic site-map structure. For example, you might want each client account to be able to view a different site map.

\
Creating a Custom Site Map Provider

Setp1: After starting [your project](https://www.mindstick.com/forum/156583/best-way-to-link-bootstrap-file-in-your-project), on solution explorers and adds a class and name it as”CounstomSiteProvider” and write down the following codes.

To accomplish this we need to inherit the StaticSiteMapProvider class and then implement our custom functionality in the class by [method overriding](https://www.mindstick.com/articles/12227/method-overloadind-and-method-overriding-in-c-sharp) which is provided by this base class. There are two methods that we need to override which are BuildSiteMap and GetRootNodeCore. The first is building the site map and the second returns the root node of the built site map.

```
using System.Web;
namespace WebApplication1{
    public class CustomSiteMapProvider : StaticSiteMapProvider    {        #region Members        private readonly object _siteMapLocking = new object();        private SiteMapNode _siteMapRootNode;        #endregion        #region Methods
        /// <summary>        /// this method is responsible for creating whole site map        /// </summary>        /// <returns> return the couston sitemap for your site </returns>
        public override SiteMapNode BuildSiteMap()        {            // Use a lock to provide thread safety            lock (_siteMapLocking)            {
                if (_siteMapRootNode != null)                {                    return _siteMapRootNode;
                }
                base.Clear();                CreateSiteMapRoot();                CreateSiteMapNodes();                return _siteMapRootNode;            }
        }
        protected override SiteMapNode GetRootNodeCore()        {            return BuildSiteMap();        }
        /// <summary>        /// create root node of your sitemap        /// in this project it sets the default.aspx as root node in sitemap        /// </summary>
        private void CreateSiteMapRoot()        {            _siteMapRootNode = new SiteMapNode(this, "Root", "~/Default.aspx", "Root");
            AddNode(_siteMapRootNode);
        }
        /// <summary>        /// this method create all chiled node of root node        /// </summary>
        private void CreateSiteMapNodes()        {            SiteMapNode node = null;            for (int i = 1; i <= 3; i++)            {
                node = new SiteMapNode(this,                    string.Format("Child{0}", i),                    string.Format("~/WebForm{0}.aspx", i),                    string.Format("Child{0}", i));
                AddNode(node, _siteMapRootNode);            }
        }
        #endregion
    }

}
```

Step 2: Now deploying the Custom Site Map Provider in web.Config file. As

```
<system.web>
    <compilation debug="true" targetFramework="4.0" />    <siteMap defaultProvider="CustomSiteMapProvider" enabled="true">      <providers>        <clear/>        <add name="CustomSiteMapProvider" type="WebApplication1.CustomSiteMapProvider"/>
      </providers>    </siteMap>  </system.web>
```

Step 3:Now add a site1.[master page](https://www.mindstick.com/blog/258/set-property-value-on-master-page-from-content-page) in your project and adds number of content pages you want to add in [your website](https://www.mindstick.com/articles/12990/ssl-certificate-why-you-need-one-for-your-website).

\
![Implementing ASP.NET Custom Site-Map](https://www.mindstick.com/blogs/c5f00dae-0156-48d8-9471-9ef0ab258b9f/images/46ffabb1-9f9e-4dfe-964b-5cde1ff64a05.png)

\

Step 4: Open site1.master and add treeView control from tool box and select data source attribute(from design view you can select it).

\
![Implementing ASP.NET Custom Site-Map](https://www.mindstick.com/blogs/c5f00dae-0156-48d8-9471-9ef0ab258b9f/images/a299bad0-3f6b-4e79-856b-9c848586382a.png)

\

Step 5: Choose SiteMap and click on ok button.

\
![Implementing ASP.NET Custom Site-Map](https://www.mindstick.com/blogs/c5f00dae-0156-48d8-9471-9ef0ab258b9f/images/f5391853-8459-4035-9e7a-260017f62124.png)

\

Step 6: The source of site1.master will be displayed as follow.

```
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication1.Site1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">    <title></title>    <asp:ContentPlaceHolder ID="head" runat="server">    </asp:ContentPlaceHolder></head><body>    <form id="form1" runat="server">    <div>        <table border="1" width="100%">            <tr>                <td height="100px">         <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1">
                    </asp:TreeView>                    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
                </td>            </tr>        </table>        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>    </div>    </form></body></html>
```

Step 7: Finally build and run your project the following navigation (sitemap will be display)

\
This article is intended to explore the basic pathways toward the custom sitemap creation; however you can create more complicated/according to your need. But this article is only for first basic steps for creating the custom sitemaps.

\
I hope you have learned how to do so very precisely understand the basics of custom site mapping.

##### Thanks.

---

Original Source: https://www.mindstick.com/blog/571/implementing-asp-dot-net-custom-site-map

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
