Adding nodes to mvcsitemap in code

I am building a simple CMS that stores the navigation/sitemap/site structure in a database table. When the app starts up I can create my sitemap nodes dynamically based on the data from that table.

The problem I am having is when a new record is added to the table or an existing one is updated while the app is running I need to rebuild the sitemap structure. Seems simple enough but I cannot figure out how.

Answers


There is no built-in support of clearing/rebuilding the sitemap on-the-fly. But you could implement this yourself quite easily by implementing a custom sitemapprovider deriving from MvcSiteMapProvider.DefaultSiteMapProvider, and create a method used to clear the cache, using the protected Clear() method. Example:

public class CustomSiteMapProvider : DefaultSiteMapProvider
{
  public void ClearSiteMap()
  {
    Clear();
  }
}

I haven't tried it but it should work. Remember to changed the web.config file to use the custom sitemapprovider instead of DefaultSiteMapProvider.


Need Your Help

Youtube analytics sample request iOS

ios google-analytics youtube-api

So I've sent a request to the youtube data api and it works like a charm, absolutely no problem there. I copied and pasted the same text and then modified to what I believe to be a satisfactory ana...

nodeapi insert and presave

php drupal drupal-6

I've got the weirdest glitch. I'm using nodeapi and targetting the story node type. I have insert case before the presave case, where presave is being used instead of update.