简体   繁体   English

在项目中使用两个web.sitemap

[英]Using two web.sitemap in a project

I want to use two different web.sitemap in one application. 我想在一个应用程序中使用两个不同的web.sitemap。 (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: (在我的母版页中创建了一个引导导航栏,我想要不同的布局默认页等),因此msdn说您必须在web.config msdn文档中添加一个新的web.sitemap和一个密钥,所以这样做后我不确定如何查询到新的web.sitemap,因为我阅读了原始的如下:

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. 我所希望的是无需更改太多代码即可阅读新的web.sitemap。

Can someone point me in the right direction? 有人可以指出我正确的方向吗?

Thanks in advance. 提前致谢。

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. 接下来,我只是将asp:sitemapdatasource添加到页面,并使用您在配置文件中指定的正确名称。

then if you have an asp:menu, asp:repeater or any other control you can use datasourceid to connect it with the asp:sitemapdatasource 然后,如果您有一个asp:menu,asp:repeater或任何其他控件,则可以使用datasourceid将其与asp:sitemapdatasource连接

SiteMapDataSource test = new SiteMapDataSource();
        test.Provider.RootNode

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 使用SiteMap类(如问题中使用的示例),您可以通过编程方式访问其他web.sitemap并阅读

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

Thanks to @Davy Quyo that confirm me the first step: adding the provider into web.config 感谢@Davy Quyo确认了我的第一步:将提供程序添加到web.config

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM