ASP.NET MVC and CreateArea Extension Method on Restricted Hosting

January 19, 2010 · 1 min read

I've recently switched hosting providers at the company I work for. Instead of being able to use wildcard mapping or the .mvc file extension mapping, I'm left with .aspx.

The premise of this exercise is easily explained here: http://www.asp.net/learn/mvc/tutorial-08-cs.aspx, specifically Listing #3 under the Hosted Server section.

While this is fine for a default MVC1 project, I've currently implemented Phil Haack's Areas v1 prototype with Steve Sanderson's CreateArea extension method located here http://blog.codeville.net/2008/11/05/app-areas-in-aspnet-mvc-take-2/.

To make the Global.asax change from Listing #3 in the first link (phew), you need to modify all routes to add the .aspx extension. The same goes true for .mvc.

I followed Steve's example verbatim and eliminated the default "" (blank) route because isn't necessary in wildcard mapping. What isn't readily apparent is that you absolutely need this when you do get into file extensions.

The fix is a simple but because it felt like the same route/area I didn't think it would work.

routes.CreateArea("Root", "Namespace.Controllers",
    routes.MapRoute(null, string.Empty,
    new { controller = "Home", action = "Index", id = string.Empty })
);

RouteDebug confirmed it gets hit properly so that should be all you need. I haven't tested to see whether you can just add this route and leave it for both file extension and wildcard mapping but it shouldn't be a problem to just add it and leave it.