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 (
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
<add name="W1" type="System.Web.XmlSiteMapProvider"
<add name="W2" type="System.Web.XmlSiteMapProvider"
Now, we have to use
<asp:sitemappath> tag this way:
<asp:SiteMapPath ID="siteMap1" SiteMapProvider="W1" runat="server"/>
<asp:SiteMapPath ID="siteMap2" SiteMapProvider="W2" runat="server"/>
Using this method, we can use more than one
SiteMapPath in a single web project.
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 firstname.lastname@example.org. Good luck!