How do I look up a SiteMapNode by its URL (or other key)?
Asked Answered
D

1

7

I think the C# ASP.NET SiteMap uses URL as a dictionary key internally since it has to lookup by URL all the time, and forces them to be unique. I want to use that lookup table, but I can't seem to find access to it.

What is the most efficient way to get a specific SiteMapNode by URL? Is there access to it?

My use case is that I want to make a navigation bar populated from the sitemap, starting with the node that's two deep from the root, in my current node's parent chain.

Dawndawna answered 26/7, 2010 at 15:7 Comment(0)
D
10

I found it. It's the SiteMapProvider class that provides the method, not SiteMap or SiteMapNode, where I was looking. See http://msdn.microsoft.com/en-us/library/system.web.sitemapprovider.findsitemapnodefromkey.aspx.

I was able to use it like this:

var node = SiteMap.Provider.FindSiteMapNodeFromKey(key);
Dawndawna answered 27/7, 2010 at 17:46 Comment(1)
Just notice that to search by Url you have to use: FindSiteMapNodeMarkel

© 2022 - 2024 — McMap. All rights reserved.