Click here to Skip to main content
15,879,474 members
Articles / Web Development / HTML

Using More than One SiteMapPath in a Single Web Project

Rate me:
Please Sign up or sign in to vote.
3.52/5 (21 votes)
16 Mar 2010CPOL1 min read 36.5K   435   15   5
There are situations when we want to break a single web project into two or more different projects, there are two or more home pages, two or more master pages, and all have their child pages. In this case, we want two or more SiteMapPath files.

Introduction

Generally we use a single Web.SiteMapPath file in a Web Project and this works as a default SiteMapPath file for whole project. We don't need to give any reference of it to <asp:SiteMapPath> tag. But there are situations when we want to break a single web project into two or more different projects, there are two or more home pages, two or more master pages, and all have their child pages. In this case, we want two or more SiteMapPath files, because each SiteMapPath file can have a single root. That’s because we cannot adjust all partitions SiteMap details into a single SiteMapPath file. This requires the use of ‘SiteMapPathProvider’ property of <asp:SiteMapPath> tag and some configuration setting in Web.Config file of that Web Project.

Using the Code

In the figure above, there’s a Web Project namely WebExample2. This web project has two folders for two different parts (Website1 and Website2) of web project. See there are two master pages and two .sitemap files.

In this case, we need to do some configuration setting in the web.config file of this web project. We must have to add this set of code in <system.web> block.

XML
<siteMap defaultProvider="W1">
    <providers>
        <add name="W1" type="System.Web.XmlSiteMapProvider"
       siteMapFile="~/Website1/Web1.sitemap"/>
        <add name="W2" type="System.Web.XmlSiteMapProvider"
       siteMapFile="~/Website2/Web2.sitemap"/>
    </providers>
</siteMap>

Now, we have to use <asp:sitemappath> tag this way:

In Web1.Master:

ASP.NET
<asp:SiteMapPath ID="siteMap1" SiteMapProvider="W1" runat="server"/>

In Web2.Master:

ASP.NET
<asp:SiteMapPath ID="siteMap2" SiteMapProvider="W2" runat="server"/>

Using this method, we can use more than one SiteMapPath in a single web project.

Final Words

I hope you will find this article helpful. For more information, you can check out the demo program available in the downloads section or you can contact me at arshad@cherisys.com. Good luck!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead Cherisys Technologies
India India
Senior Software Professional with 13+ years of experience in web/desktop applications development.

Comments and Discussions

 
GeneralMy vote of 5 Pin
JoseRegistros10-Feb-13 5:24
JoseRegistros10-Feb-13 5:24 
GeneralNice job done Pin
pamperghost3-Apr-10 1:58
pamperghost3-Apr-10 1:58 
Cool code. Hope there would be many to get help from it. I too, never know that this could happen in .net before coming to this article. great job done.Thumbs Up | :thumbsup: Thumbs Up | :thumbsup: Thumbs Up | :thumbsup: Thumbs Up | :thumbsup: Thumbs Up | :thumbsup:
GeneralMy vote of 1 Pin
Syed J Hashmi20-Jan-10 18:29
Syed J Hashmi20-Jan-10 18:29 
GeneralRe: My vote of 1 Pin
Mohd Arshad Malik24-Mar-10 4:51
Mohd Arshad Malik24-Mar-10 4:51 
GeneralRe: My vote of 1 Pin
Mohd Arshad Malik31-Mar-10 13:58
Mohd Arshad Malik31-Mar-10 13:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.