I have two areas:
ControlPanel
and Patients
.
Both have a controller called ProblemsController that are similar in name only. The desired results would be routes that yield /controlpanel/problems => MyApp.Areas.ControlPanel.Controllers.ProblemsController and /patients/problems => MyApp.Areas.Patients.Controllers.ProblemsController.
Each has routes configured like this:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"**Area Name Here**_default",
"**Area Name Here**/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
where *****Area Name Here***** is either ControlPanel or Patients.
When I go to /patients/problems/create (for example), I get a 404 where the routing error says: A public action method 'create' was not found on controller 'MyApp.Areas.ControlPanel.Controllers.ProblemsController'
.
I'm not sure what I'm doing wrong.
Actually, it turns out the problem is with Autofac 2.1's AutofacControllerFactory
. The routes are working correctly, but autofac is having a hard time finding the right controller.
For those that are using Autofac and MVC 2.0, Autofac 2.1 doesn't have support for areas. If your project is simple enough, Autofac may appear to work with areas, but it will start breaking down as your areas and controllers become more sophisticated.
The ticket for full Area support has been closed and the related code checked in, but from what I can tell it won't be released until 2.2. I'm going to try building from the trunk and I'll report back how it goes.
UPDATE Yep, everything looks good using Autofac built from the trunk. Hopefully 2.2 will be officially released soon.
Have you tried using the overload with the namespaces parameter?
ASP.NET MVC 2 Preview 2: Areas duplicate controller problem
精彩评论