views:

432

answers:

3
+2  Q: 

ASP.NET Site Maps

Has anyone got experience creating SQL-based ASP.NET site-map providers?

I've got the default XML web.sitemap file working properly with my Menu and SiteMapPath controls. But I'll need a way for the users of my site to create and modify pages dynamically. I'll need to tie page viewing permissions into the standard ASP.NET membership system as well.

I'd like some advice on articles to read or video clips to watch.

+4  A: 

Microsoft has one - have you tried it?

Greg Hurlman
That's probably exactly what I need. I'll read up on it. Thank you.
Zack Peterson
+6  A: 

I wrote a dynamic sitemap class a while ago, and blogged about it here: http://harriyott.com/2007/03/adding-dynamic-nodes-to-aspnet-site.aspx

harriyott
+1  A: 

The Jeff Prosise version from MSDN magazine works pretty well, but it has a few flaws:

AddNode freaks out with links to external sites on your menu (www.google.com, etc.)

Here's my fix in BuildSiteMap():

SiteMapNode node = GetSiteMapNodeFromReader(reader);
string url = node.Url;
if (url.Contains(":"))
{
    string garbage = Guid.NewGuid().ToString();  // SiteMapNode needs unique URLs
    node.Url = "~/dummy_" + garbage + ".aspx";
    AddNode(node, _root);
    node.Url = url;
}
else
{
    AddNode(node, _root);
}

SQLDependency caching is cool, but if you don't want to make a trip to the DB everytime your menu loads (to check to see if the dependency has changed) and your menus don't change very often, then why not use HttpRuntime.Cache instead?

public override SiteMapNode RootNode
{
    get
    {
        SiteMapNode temp = (SiteMapNode)HttpRuntime.Cache["SomeKeyName"];
        if (temp == null)
        {
            temp = BuildSiteMap();
            HttpRuntime.Cache.Insert("SomeKeyName", temp, null, DateTime.Now.AddHours(1), Cache.NoSlidingExpiration);
        }
        return temp;
    }
}
Kelly Adams