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.
<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!
Senior Software Professional with 13+ years of experience in web/desktop applications development.