Utility classes designed for ASP.NET MVC; deals with encryption, routing, caching, authorization, and various other security issues. Designed to used with Dependency Injection in ASP.NET MVC3.
C# Ruby
Latest commit b8f429e Dec 25, 2012 @Aaronontheweb Merge pull request #11 from Asher435/master
Updated README.md
Failed to load latest commit information.
.nuget added Nuget package restore Sep 14, 2012
MVC.Utilities.Azure Implemented bulk get behavior for AppFabric Cache Sep 15, 2012
MVC.Utilities.BCrypt Made it so all projects in MVC.Utilities pull their version informati… Sep 14, 2012
MVC.Utilities.Memcached.Tests Made it so all projects in MVC.Utilities pull their version informati… Sep 14, 2012
MVC.Utilities.Memcached Added a default constructor for MemcachedService Sep 15, 2012
MVC.Utilities.Tests Renamed the RuntimeCacheProvider to RuntimeCacheService; also provide… Sep 14, 2012
MVC.Utilities Renamed the RuntimeCacheProvider to RuntimeCacheService; also provide… Sep 14, 2012
buildscripts updated the package dependency information in the Rakefile for MVC.Ut… Sep 15, 2012
tools added all of the unit runners to the solution Sep 14, 2012
.gitignore fixed some issues with our output tasks (precursors for nuget packaging) Sep 14, 2012
Gemfile added a Gemfile and fixed a lot of issues with the Rakefile Sep 14, 2012
Gemfile.lock added a Gemfile and fixed a lot of issues with the Rakefile Sep 14, 2012
MVC.Utilities.1.1.dotCover Added dotCover file Dec 11, 2011
MVC.Utilities.sln added Nuget package restore Sep 14, 2012
README.textile Fixed a punctuation error in README.textfile Dec 25, 2012
SharedAssemblyInfo.cs version 1.13.5 Sep 15, 2012
VERSION version 1.13.5 Sep 15, 2012
license.txt Initial commit. Patches welcome! Aug 6, 2011
mvc-utilities-azure.nuspec Updated assembly info and nuget packages Feb 15, 2012
mvc-utilities-bcrypt.nuspec Updated assembly info and nuget packages Feb 15, 2012
mvc-utilities.nuspec Updated package to 1.08 Jun 13, 2012
package.cmd Upgraded package.cmd to suppor the NuGet 1.6 command line options Feb 15, 2012
rakefile.rb version 1.13.4 Sep 15, 2012



This is a batch of utility classes for making it easier to work with ASP.NET MVC.


Create a new FormsAuthenticationService instance thusly, or inject it via an IoC container:

var authenticator = new FormsAuthenticationService();

You can sign-in users and set a persistent ASP.NET Forms authentication cookie:

authenticator.SignIn(UserName, true);

You can sign-out users again, which clears the authentication cookie:



MVC.Utilities supports a couple of different caching options out of the box, all of which derive from the ICacheService interface and CacheServiceBase abstract base class.

The RuntimeCacheService uses the System.Runtime.Caching namespace to take advantage of built-in object caching – this is cache is simply an abstracted, more testable version of ASP.NET’s built-in object caching.

Create a new RuntimeCacheService instance – specify the type of ObjectCache you want to use and a default expiration window:

var cacheService = new RuntimeCacheProvider(MemoryCache.Default, new TimeSpan(0, 0, 20));

Use the Save, Exists, Get, and Delete methods to act on objects in dictionary maintained by the cache. These commands will all work as expected for the AppFabricCacheService as well for those of you using Windows Azure


MVC.Utilities has two out-of-the-box encrpytion providers which both derive from the ICryptoService interface: HMACSHA1Service and BCryptService.

To hash a password, simply call the HashPassword method:

var hash = _crypto.HashPassword(originalPass);

To check to see if two passwords are equivalent, use the CheckPassword method:

var areEquivalent = _crypto.CheckPassword(originalPass, hash);


MVC.Utilities contains a set of helper classes designed to tackle some specific routing challenges in ASP.NET MVC, particularly where search engine optimization is concerned.

Lowercase Routes

Courtesy of Nick Bernardi, we have the LowerCaseRoute class in MVC.Utilities.

Here’s an example of how to use it inside of Global.asax:

routes.Add(“default”, new LowerCaseRoute(“{controller}/{action}/{id}”,
new RouteValueDictionary(
new { controller = “Home”, action = “Index”, id = UrlParameter.Optional }),
new MvcRouteHandler()));

Search Engine-Friendly Slugs

For sites that serve user-generated content, some developers make it a priority to give those pages SEO-friendly URLs.

The SlugHelper utility class helps make this easy:

//slug will look like ‘complex-looking-name’ (without quotes obviously)
var slug = SlugHelper.GenerateSlug(“Complex Looking Name!!!!”);


Currently there’s only one additional security-related class in MVC.Utilities.Security: the UploadedImageValidator.

The UploadedImageValidator verifies that a user-uploaded image is an image in JPEG, GIF, or PNG format and (optionally) is under a specified file size.

var imageStream = ImageContainer.AsStream("test.jpeg");
var isValidImage = UploadedImageValidator.FileIsWebFriendlyImage(Stream stream);

UI and Display Helpers

The DateTimeLocalizationHelper provides a ghetto, server-side method for localizing times by simply displaying all times as relative times ala Hacker News.

For example, 3/3/2011 2:11 will read as “2 hours ago” if you’re looking at the content at 3/3/2011 4:14.

Simply call the ToRelativeDateTime method from your standard HTML helper class.


Install MVC.Utilities via NuGet

If you want to install MVC.Utilities via NuGet, simply type this command into the package manage console in Visual Studio:

Install-Package mvc-utilities

If you want access to the Azure-specific helpers in MVC.Utilities, install this package also:

Install-Package mvc-utilities-azure