Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Site Maps

Does anyone have experience creating SQL-based ASP.NET site-map providers?

I have the default XML file web.sitemap 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 need to tie page viewing permissions into the standard ASP.NET membership system as well.

like image 700
Zack Peterson Avatar asked Aug 01 '08 15:08

Zack Peterson


People also ask

What is Sitemap in MVC?

A site map (or sitemap) is a list of pages of a web site accessible to crawlers or users. It can be either a document in any form used as a planning tool for Web design, or a Web page that lists the pages on a Web site, typically organized in hierarchical fashion.

WHAT IS A Sitemap example?

HTML Sitemap Example Just like in the XML sitemap example, an HTML sitemap lists out all the pages you want to be indexed. HTML sitemaps are multipurpose. They're usually made to look just like a regular page on your site and include a navigation menu, footer, and everything else you might expect to see on a page.

Which of the following controls displays user presence in an ASP.NET website?

The SiteMapPath control basically is used to access web pages of the website from one webpage to another.


1 Answers

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;     } } 
like image 114
Kelly Adams Avatar answered Sep 19 '22 15:09

Kelly Adams