Adventures in .NET Software Craftsmanship!

Yes, I know what everybody is thinking right now, Don't SiteMaps already provide functionality for Security Trimming? Well they do and they don't. This functionality is available only if you are using an implementation of the ASP.NET MembershipProvider and RoleProvider. In the applications that I have to work with in a day to day basis that is rarely the case, I always have to develop a custom security provider using forms or windows authentication that support some far fetched business requirements. I still however love to use SiteMaps and have rarely seen the need to customize the base SiteMap provider for any other reason. So, in order to have security trimming and still use and bind the information from my SiteMap I wrote the following block of code that just begged to be re-factored.

I decided that, because I was going to need to reuse this functionality in several places and I wanted to avoid creating a class that would perform this task specifically, that I should add a new method to the SiteMapCollection class using a C# 3.0 Extension Method.

This blog is not intended to be a tutorial, but I would like to point out the facts that C# Extension methods have to be defined in a static class as a static method and the first parameter must be the class to be extended (Notice the use of the 'this' keyword on the fist parameter).

I am in the process of getting back from the Build 2011 conference in Anaheim, California where ...

The Author

Currently a Developer Extraordinaire at InfernoRed Technology based out of Northern Virginia. I have been architecting and building software solutions using Microsoft technology for the past 14 years. I was awarded a Microsoft MVP award for C# in 2007,2008 and 2010 and currently an active participant of the Microsoft MVP reConnect program. I am originally from the Dominican Republic, and the proud father of two beautiful daughters that make my life special. You can track me down on twitter (@hernandezrobert) and on this blog at http://www.overridethis.com.