Click here to Skip to main content
14,333,853 members

Using More than One SiteMapPath in a Single Web Project

Rate this:
3.52 (21 votes)
Please Sign up or sign in to vote.
3.52 (21 votes)
16 Mar 2010CPOL
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.

Image 1

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.

<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:SiteMapPath ID="siteMap1" SiteMapProvider="W1" runat="server"/>

In Web2.Master:

<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)

Share

About the Author

Mohd Arshad Malik
Software Developer (Senior) Cherisys Technologies
India India
Senior Software Professional with 10+ years of experience in web/desktop applications development.

Comments and Discussions

 
GeneralMy vote of 5 Pin
JoseRegistros10-Feb-13 5:24
memberJoseRegistros10-Feb-13 5:24 
GeneralNice job done Pin
pamperghost3-Apr-10 1:58
memberpamperghost3-Apr-10 1:58 
GeneralMy vote of 1 Pin
Syed Javed20-Jan-10 18:29
memberSyed Javed20-Jan-10 18:29 
GeneralRe: My vote of 1 Pin
Mohd Arshad Malik24-Mar-10 4:51
memberMohd Arshad Malik24-Mar-10 4:51 
GeneralRe: My vote of 1 Pin
Mohd Arshad Malik31-Mar-10 13:58
memberMohd 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.

Article
Posted 14 Jun 2008

Stats

32.7K views
15 bookmarked