Logo

Maarten Balliauw {blog}

ASP.NET, ASP.NET MVC, Azure, PHP, OpenXML, VSTS, ...

About the author

Maarten Balliauw is currently employed as .NET Technical Consultant at RealDolmen. His interests are mainly web applications developed in ASP.NET (C#) or PHP and the Windows Azure cloud platform.
More about me More about me
Send mail E-mail me


ASP.NET MVC Quickly Subscribe to my RSS feed Follow me on Twitter! View Maarten Balliauw's profile on LinkedIn
View Maarten Balliauw's MVP profile

Search

Latest Twitter

    Follow me on Twitter...

    My projects

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

    © Copyright Maarten Balliauw 2010

    ASP.NET MVC MvcSiteMapProvider 1.0 released

    image Back in March, I blogged about an experimental MvcSiteMap provider I was building. Today, I am proud to announce that it is stable enough to call it version 1.0! Download MvcSiteMapProvider 1.0 over at CodePlex.

    Ever since the source code release I did back in March, a lot of new features have been added, such as HtmlHelper extension methods, attributes, dynamic parameters, … I’ll leave most of them up to you to discover, but there are some I want to quickly highlight.

    kick it on DotNetKicks.com

    ACL module extensibility

    By default, MvcSiteMap will make nodes visible or invisible based on [Authorize] attributes that are placed on controllers or action methods. If you have implemented your own authentication mechanism, this may no longer be the best way to show or hide sitemap nodes. By implementing and registering the IMvcSiteMapAclModule interface, you can now plug in your own visibility logic.

    public interface IMvcSiteMapAclModule
    {
        /// <summary>
        /// Determine if a node is accessible for a user
        /// </summary>
        /// <param name="provider">The MvcSiteMapProvider requesting the current method</param>
        /// <param name="context">Current HttpContext</param>
        /// <param name="node">SiteMap node</param>
        /// <returns>True/false if the node is accessible</returns>

        bool IsAccessibleToUser(MvcSiteMapProvider provider, HttpContext context, SiteMapNode node);
    }

    Dynamic parameters

    Quite often, action methods have parameters that are not really bound to a sitemap node. For instance, take a paging parameter. You may ignore this one safely when determining the active sitemap node: /Products/List?page=1 and /Products/List?page=2 should both have the same menu item highlighted. This is where dynamic parameters come in handy: MvcSiteMap will completely ignore the specified parameters when determining the current node.

    <mvcSiteMapNode title="Products" controller="Products" action="List" isDynamic="true" dynamicParameters="page" />

    The above sitemap node will always be highlighted, whatever the value of “page” is.

    SiteMapTitle action filter attribute

    In some situations, you may want to dynamically change the SiteMap.CurrentNode.Title in an action method. This can be done manually by setting  SiteMap.CurrentNode.Title, or by adding the SiteMapTitle action filter attribute.

    Imagine you are building a blog and want to use the Blog’s Headline property as the site map node title. You can use the following snippet:

    [SiteMapTitle("Headline")]
    public ViewResult Show(int blogId) {
       var blog = _repository.Find(blogIdId);
       return blog;
    }

    You can also use a non-strong typed ViewData value as the site map node title:

    [SiteMapTitle("SomeKey")]
    public ViewResult Show(int blogId) {
       ViewData["SomeKey"] = "This will be the title";

       var blog = _repository.Find(blogIdId);
       return blog;
    }

    HtmlHelper extension methods

    MvcSiteMap provides different HtmlHelper extension methods which you can use to generate SiteMap-specific HTML code on your ASP.NET MVC views. Here's a list of available HtmlHelper extension methods.

    • HtmlHelper.Menu() - Can be used to generate a menu
    • HtmlHelper.SiteMap() - Can be used to generate a list of all pages in your sitemap
    • HtmlHelper.SiteMapPath() - Can be used to generate a so-called "breadcrumb trail"

    The MvcSiteMap release can be found on CodePlex.

    kick it on DotNetKicks.com


    Categories: ASP.NET | C# | General | MVC | Projects

    Comments

    Elijah Manor United States | Reply

    Friday, September 04, 2009 2:44 PM

    Elijah Manor

    Were you able to support multiple dynamic levels for the menu (example: maximumDynamicDisplayLevels)?

    F.Y.I. This will be tech tweeted at 11:00AM CST

    maartenba Belgium | Reply

    Thursday, June 17, 2010 2:15 PM

    maartenba

    Ah no, forgot that one. Can you add it as a feature request again?

    Maarten Belgium | Reply

    Friday, September 04, 2009 2:55 PM

    Maarten

    If you mean this one: mvcsitemap.codeplex.com/.../View.aspx yes it is in Smile

    progg.ru | Reply

    Friday, September 04, 2009 6:11 PM

    trackback

    ASP.NET MVC MvcSiteMapProvider 1.0 released

    Thank you for submitting this cool story - Trackback from progg.ru

    DotNetShoutout | Reply

    Friday, September 04, 2009 9:13 PM

    trackback

    ASP.NET MVC MvcSiteMapProvider 1.0 released - Maarten Balliauw

    Thank you for submitting this cool story - Trackback from DotNetShoutout

    Kian Ryan United Kingdom | Reply

    Saturday, September 05, 2009 11:09 AM

    Kian Ryan

    I've been using this since the early days of its release for a couple of projects.  It's been a bit of a godsend, and patches a hole that frankly, shouldn't have been there.  I'm glad it's made it to 1.0.

    Awesome.

    Kazi Manzur Rashid's Blog | Reply

    Sunday, September 06, 2009 11:07 AM

    trackback

    ASP.NET MVC and Authorization and Monkey Patching

    As you know that we will be including Menu in our final release , when defining the menu, it will allow

    9eFish | Reply

    Sunday, September 06, 2009 1:24 PM

    trackback

    ASP.NET MVC MvcSiteMapProvider 1.0 released

    9efish.感谢你的文章 - Trackback from 9eFish

    Sanjeev Agarwal | Reply

    Monday, September 07, 2009 12:06 PM

    trackback

    Daily tech links for .net and related technologies - September 4-8, 2009

    HTML clipboard Daily tech links for .net and related technologies - September 4-8, 2009 Web Development

    Jack United States | Reply

    Monday, September 21, 2009 11:11 AM

    Jack

    Great, it will save us lots of time in asp.net MVC

    #.think.in | Reply

    Friday, October 02, 2009 3:32 PM

    trackback

    #.think.in infoDose #42 (3rd September - 10th September)

    #.think.in infoDose #42 (3rd September - 10th September)

    Microsoft RealDolmen blogs | Reply

    Wednesday, October 28, 2009 3:07 PM

    trackback

    ASP.NET MVC MvcSiteMapProvider 1.0 released

    ASP.NET MVC MvcSiteMapProvider 1.0 released

    Add comment




      Country flag

    biuquote
    • Comment
    • Preview
    Loading