SiteMap 更改 SiteMapProvider?
我有一个从 web.sitemap 文件构建的自定义菜单导航,第一行类似于:
SiteMapNodeCollection topLevelNodes = SiteMap.RootNode.ChildNodes;
这有效 - 它从 web.sitemap 文件获取所有顶级节点,并允许我查看每个节点SiteMapNode 并做一些事情。
但是,现在我希望能够创建多个 web.sitemap 文件,然后以编程方式确定要使用哪个 web.sitemap 文件,但我似乎不知道如何执行此操作。我假设我可以创建一个自定义 SiteMapProvider 来执行逻辑来确定要加载哪个 web.sitemap 文件,或者我有多个提供程序,每个提供程序都将 SiteMapFile 属性设置为特定的 *.sitemap 文件,然后切换在我访问 SiteMap.RootNode 之前以编程方式访问提供程序。
我认为拥有一个自定义提供程序可能更容易,然后覆盖它查找实际物理站点地图文件位置的部分,但我不清楚如何做到这一点,
我已经用谷歌搜索了很多,但大多数答案似乎是关于标准 sitemappath 控件等,以及如何设置 SiteMapDataSource,我认为这与我的方法无关。
I've got a custom menu navigation built from a web.sitemap file, the first line of this would be something like:
SiteMapNodeCollection topLevelNodes = SiteMap.RootNode.ChildNodes;
This works - it gets all the top level nodes from the web.sitemap file, and allows me to look through each SiteMapNode and do stuff.
However, now I want to be able to create multiple web.sitemap files, and then programmatically determine which web.sitemap file to use, but I can't seem to find out how to do this. I'm assuming I could either create one custom SiteMapProvider that can perform the logic to determine which web.sitemap file to load, or I have multiple providers, each one with the SiteMapFile property set to a specific *.sitemap file, and then switch providers programmatically before I access SiteMap.RootNode.
I think it's probably easier to have one custom provider, and then override the part where it looks for the actual physical sitemap file location, but I'm unclear how I would do this
I've googled a lot, but most answers seem to be regarding the standard sitemappath controls and so on, and how to set a SiteMapDataSource, which I don't think is relevant to my approach.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您需要在 web.config 中指定所有站点地图文件,如下所示:
然后在代码隐藏中,您可以动态地将 SiteMapDataSource(绑定到菜单)分配给您在 web.config 中指定的提供程序之一:
.aspx
.cs
First you need to specify all of your sitemap files in your web.config as such:
Then in your code-behind you can dynamically assign your SiteMapDataSource (which is bound to your menu) to one of the providers you specified in your web.config:
.aspx
.cs
泡利的评论是对我的特殊要求的回答:
我没有意识到这是可能的,但对我来说这是正确的解决方案。
Pauli's comment was the answer to my particular requirement:
I hadn't realised this was possible, but was the correct solution for me.