SiteMap Path example in ASP.NET

December 22, 2014 0 Comments

Using the SiteMap Path class you can navigate a website. It displays a set of Text or images Hyperlinks. Inheritance hierarchy of SiteMapPath class are:

Lets take an simple example of SiteMap Path 

To create Web.Sitemap, right click the website name. A context menu appears. Select the Add New Item option from the context menu. The Add New Item dialog box appear. Select Site Map from the option available. This will create a new web.sitemap file in the website.

 The Web.sitemap file consists of navigational details for an application. You can set the title, URL, and other information for each page by using the Web.sitemap file. code, copy and paste into your sitemap file.

Article : How to use Menu Control in ASP.NET

Video : A simple video contain how to use menu and sitemap file

  <?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="" >
    <siteMapNode url="~/Default.aspx" title="Home Page"  description="">
        <siteMapNode url="~/About.aspx" title="About"  description="" />
        <siteMapNode url="~/contact.aspx" title="contact us"  description="" />

After that Add a master page and three web form(Default.aspx, About.aspx, contact.aspx)  into the website folder. Here we take ASP.NET website , which is contain default template. After Completed your sitemap file you can add sitemap path control to the master page.

Note : Add SiteMap Path control into the master page after navigation control

Master page source code , where your sitemap path control exists

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMaster" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" xml:lang="en">
<head runat="server">
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    <form runat="server">
    <div class="page">
        <div class="header">
            <div class="title">
                    My ASP.NET Application
            <div class="loginDisplay">
                <asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
                        [ <a href="~/Account/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ]
                        Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
                        [ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
            <div class="clear hideSkiplink">
                <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
                        <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
                        <asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
        <div class="main">
            <asp:SiteMapPath ID="SiteMapPath2" runat="server">
            <br />
            <asp:ContentPlaceHolder ID="MainContent" runat="server"/>
        <div class="clear">
    <div class="footer">

Code Generate the following output

SiteMap Path in ASP.NET

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google