Search code examples
c#asp.netasp.net-3.5sitemapsitemapprovider

Faking SiteMap.CurrentNode to use another existing SiteMapNode


My site is dynamically creating the sitemap from both database and xml data. This is working great, however, for a portion of the site that lists news articles it was decided to not put the news article detail pages in the site map. So if you were to click on the title of a news article (from the listing page that is in the sitemap) it would take you to the page with the article, but that page/url is not in the sitemap.

I have controls and logic in the master pages that use

SiteMap.CurrentNode

Essentially, on page load I would like to change SiteMap.CurrentNode to the node of the news article listing page (which is in the sitemap). So essentially all of the logic running on this page will treat the page as if it was the listing page. I can't find anyway to do this.

This code will get me the node that I want as I know its key.

SiteMapDataSource siteMapDataSource1 = new SiteMapDataSource();
    siteMapDataSource1.SiteMapProvider = "Main";
    SiteMapNode newsListingPageNode = siteMapDataSource1.Provider.FindSiteMapNodeFromKey(siteMapKey);

So basically I wish I could do this:

SiteMap.CurrentNode = newsListingPageNode;

But CurrentNode can't be set.

Any suggestions on how I could do this? I appreciate the help.


Solution

  • According to this article, you can create a custom handler for the SiteMapResolve event, and presumably you could return a custom node from that.