0

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.

Robert K
  • 130
  • 3
  • 16

2 Answers2

0

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
Davy Quyo
  • 41
  • 2
  • Ok but having the sitemapdatasource how to programmatically obtain the root node? – Robert K Sep 09 '15 at 13:57
  • I updated my answer. created a new datasource and showed you how to get rootnode from that. you adapt code to use rootnode of existing sitemapdatasource on page. – Davy Quyo Sep 09 '15 at 15:09
0

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

Robert K
  • 130
  • 3
  • 16