Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 491
Scott Stafford Avatar asked Jul 26 '10 15:07

Scott Stafford


1 Answers

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);
like image 178
Scott Stafford Avatar answered Sep 28 '22 06:09

Scott Stafford