【问题标题】:Different controllers with the same name in two different areas results in a routing conflict两个不同区域同名的不同控制器导致路由冲突
【发布时间】:2010-04-26 06:31:39
【问题描述】:

我有两个领域:

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 }
            );
        }

这里 ***** 区域名称 ***** 是 ControlPanel 或患者。

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

我不确定自己做错了什么。

【问题讨论】:

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


    【解决方案1】:

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

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

    完整区域支持的票已关闭,相关代码已签入,但据我所知,它要到 2.2 才会发布。我将尝试从树干构建,我会报告它的进展情况。

    更新 是的,使用从树干构建的 Autofac 一切看起来都很好。希望2.2能尽快正式发布。

    【讨论】:

      【解决方案2】:

      您是否尝试过将重载与命名空间参数一起使用?

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

      【讨论】:

        猜你喜欢
        • 2017-03-12
        • 1970-01-01
        • 1970-01-01
        • 2014-10-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多