两个不同区域中具有相同名称的不同控制器会导致路由冲突

时间:2010-04-26 06:31:39

标签: asp.net-mvc-2 asp.net-mvc-routing autofac asp.net-mvc-areas

我有两个方面:

ControlPanelPatients

两者都有一个名为ProblemsController的控制器,名称相似。期望的结果将是产生/ controlpanel / problems =>的路线。 MyApp.Areas.ControlPanel.Controllers.ProblemsController和/ patients / problems => MyApp.Areas.Patients.Controllers.ProblemsController。

每个都有如下配置的路线:

public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "**Area Name Here**_default",
                "**Area Name Here**/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }
            );
        }

其中***** Area Name这里*****是ControlPanel或者患者。

当我转到/ patients / problems / create(例如)时,我得到一个404,其中路由错误显示为:A public action method 'create' was not found on controller 'MyApp.Areas.ControlPanel.Controllers.ProblemsController'

我不确定我做错了什么。

2 个答案:

答案 0 :(得分:1)

实际上,问题在于Autofac 2.1的AutofacControllerFactory。路由工作正常,但autofac很难找到合适的控制器。

对于那些使用Autofac和MVC 2.0的用户,Autofac 2.1不支持区域。如果您的项目足够简单,Autofac可能出现以处理区域,但随着您的区域和控制器变得更加复杂,它将开始崩溃。

已经关闭了完整区域支持的票证并签入了相关代码,但据我所知,它将在2.2之前发布。我将尝试从行李箱建造,我会报告它是如何发生的。

<强>更新 是的,使用从后备箱构建的Autofac,一切看起来都很好。希望2.2即将正式发布。

答案 1 :(得分:0)

您是否尝试过使用namespaces参数?

ASP.NET MVC 2 Preview 2: Areas duplicate controller problem