Search code examples
c#asp.netwebformsweb-configweb.sitemap

Using two web.sitemap in a project


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.


Solution

  • 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