Skip to content
Go back

MvcSiteMapProvider 2.2.0 released

Edit page

I’m proud to announce that MvcSiteMapProvider 2.2.0 has just been uploaded to CodePlex. It should also be available through NuPack in the coming hours. This release has taken a while, but that’s because I’ve been making some important changes...

MvcSiteMapProvider is, as the name implies, an ASP.NET MVC SiteMapProvider implementation for the ASP.NET MVC framework. Targeted at ASP.NET MVC 2, it provides sitemap XML functionality and interoperability with the classic ASP.NET sitemap controls, like the SiteMapPath control for rendering breadcrumbs and the Menu control.

In this post, I’ll give you a short update on what has changed as well as some examples on how to use newly introduced functionality.

Changes in MvcSiteMapProvider 2.2.0

Templated HtmlHelpers

The MvcSiteMapProvider provides different HtmlHelper extension methods which you can use to generate SiteMap-specific HTML code on your ASP.NET MVC views like a menu, a breadcrumb (sitemap path), a sitemap or just the current node’s title.

All helpers in MvcSiteMapProvider are make use of templates: whenever a node in a menu is to be rendered, a specific partial view is used to render this node. This is based on the idea of templated helpers. The default templates that are used can be found on the downloads page. Locate them under the Views/DisplayTemplates folder of your project to be able to customize them.

When creating your own templates for MvcSiteMapProvider's helpers, the following model objects are used and can be templated:

The following template is an example for rendering a sitemap node represented by the MvcSiteMapProvider.Web.Html.Models.SiteMapNodeModel model.

Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/

—> 1 <%@ Control Language=C# Inherits=System.Web.Mvc.ViewUserControl<MvcSiteMapProvider.Web.Html.Models.SiteMapNodeModel> %> 2 <%@ Import Namespace=System.Web.Mvc.Html %> 3 4 <% if (Model.IsCurrentNode && Model.SourceMetadata[HtmlHelper].ToString() != MvcSiteMapProvider.Web.Html.MenuHelper) { %> 5 <%=Model.Title %> 6 <% } else if (Model.IsClickable) { %> 7 <a href=”<%=Model.Url %>”><%=Model.Title %></a> 8 <% } else { %> 9 <%=Model.Title %> 10 <% } %>

New extensibility point

In the previous release, a number of extensibility points have been introduced. I blogged about them before. A newly introduced extensibility point is the ISiteMapProviderEventHandler . A class implementing MvcSiteMapProvider.Extensibility.ISiteMapProviderEventHandler can be registered to handle specific events, such as when adding a SiteMapNode.

Here’s an example to log all the nodes that are being added to an MVC sitemap:

Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/

—> 1 public class MySiteMapProviderEventHandler : ISiteMapProviderEventHandler 2 { 3 public bool OnAddingSiteMapNode(SiteMapProviderEventContext context) 4 { 5 // Should the node be added? Well yes! 6 return true; 7 } 8 9 public void OnAddedSiteMapNode(SiteMapProviderEventContext context) 10 { 11 Trace.Write(Node added: + context.CurrentNode.Title); 12 } 13 }

Optimized sitemap XML for SEO

Generating a search-engine friendly list of all nodes in a sitemap was already possible. This functionality has been vastly improved with two new features:

For example, if a website contains more than 50.000 nodes, the sitemap XML that is generated will look similar to the following:

Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/

—>1 <?xml version=“1.0” encoding=“utf-8” ?> 2 <sitemapindex xmlns=“http://www.sitemaps.org/schemas/sitemap/0.9> 3 <sitemap> 4 <loc>http://localhost:1397/sitemap-1.xml</loc> 5 </sitemap> 6 <sitemap> 7 <loc>http://localhost:1397/sitemap-2.xml</loc> 8 </sitemap> 9 </sitemapindex>

This sitemap index links to sub-sitemap files where all nodes are included.


Edit page
Share this post on:

Previous Post
Writing for the Windows Azure for PHP portal
Next Post
Scale-out to the cloud, scale back to your rack