Using two web.sitemap in a project

1.1k Views Asked by At

I want to use two different web.sitemap in one application. (a bootstrap navbar is create in my master page, i want different layout default pages etc) So msdn says that you must add a new web.sitemap and a key in the web.config msdn documentation so after doing that im not sure how to query to the new web.sitemap because i read the original one as follows:

SiteMapNode rootNode = SiteMap.RootNode;
makeNavbar(rootNode.ChildNodes, true, false);
....

And its ok... the navbar its created all fine here...

But what i want is something like:

SiteMapBode rootNode = SiteMap.UseProvider("newSiteMap").RootNode;

obviously that function doesnt exist...

All i want its to read the new web.sitemap without change too much code.

Can someone point me in the right direction?

Thanks in advance.

2

There are 2 best solutions below

2
Davy Quyo On BEST ANSWER

This in your config.

    <siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
          <providers>
            <clear />
            <add name="XmlSiteMapProvider" type="System.Web.XmlSiteMapProvider" siteMapFile="Web.sitemap" />
            <add name="XmlSiteMapProvider2" type="System.Web.XmlSiteMapProvider" siteMapFile="secondsitemapname.sitemap" />
          </providers>
        </siteMap>

next thing I do is just add asp:sitemapdatasource to the page with the correct name you gave in the config file.

then if you have an asp:menu, asp:repeater or any other control you can use datasourceid to connect it with the asp:sitemapdatasource

SiteMapDataSource test = new SiteMapDataSource();
        test.Provider.RootNode
0
Robert K On

Well i found the solution. Using the SiteMap class like the example used in the question you can access programmatically to the different web.sitemap and read

SiteMapNode rootNode = SiteMap.Providers["SiteMap2"].RootNode;

Thanks to @Davy Quyo that confirm me the first step: adding the provider into web.config