views:

20

answers:

1

I'm trying to route to the home page of an Area in MVC, e.g.

myDomain.com/myArea/Home/Index

when I use the URL:

myDomain.com/myArea

MVC appears to by trying to find a Controller called "myArea" in the root Controllers folder and thereby would route to:

myDomain.com/myArea/Index

if the Controller existed.

Again, I want:

myDomain.com/myArea

to route to:

myDomain.com/myArea/Home/Index

I figure that I should be able to do this in Global.asax without having to resort to creating a dummy controller that re-routes to the area controller, but I've drawn a blank.

A: 

One way I used to get around this was to set the namespaces property on the default route in the Global RegisterRoutes method, this seemed to resolve that problem. Had to add this restriction to some other routes where I had conflicts between Controller in the main website and the area.

var namespaces = new[] { "CompiledExperience.Website.Web.Controllers" };

routes.MapRoute("Default", "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    namespaces
);
Nigel Sampson
Yes, I already tried that, but it made no difference. I made sure I restarted IIS to ensure that the routes were re-registered. Thanks though.
Moose Factory