两个不同区域的不同控制器同名导致路由冲突

发布于 2024-08-30 09:36:40 字数 852 浏览 2 评论 0原文

我有两个区域:

ControlPanelPatients

两者都有一个名为 ProblemsController 的控制器,它们仅在名称上相似。期望的结果将是产生 /controlpanel/problems => 的路线。 MyApp.Areas.ControlPanel.Controllers.ProblemsController 和 /患者/问题 => 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 }
            );
        }

其中*****此处的区域名称***** 是控制面板或患者。

当我转到 /患者/问题/创建(例如)时,我收到 404,其中路由错误显示: 在控制器 'MyApp.Areas.ControlPanel.Controllers.ProblemsController 上找不到公共操作方法 'create' '

我不确定我做错了什么。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔女人霸气范 2024-09-06 09:36:40

事实上,问题出在 Autofac 2.1 的 AutofacControllerFactory 上。路线工作正常,但 autofac 很难找到正确的控制器。

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

完整区域支持的请求已经关闭,相关代码也已签入,但据我所知,它要到 2.2 才会发布。我将尝试从后备箱进行构建,然后我会报告进展情况。

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

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.

戏剧牡丹亭 2024-09-06 09:36:40

您是否尝试过使用带有名称空间参数的重载?

ASP.NET MVC 2 预览版 2:区域重复控制器问题

Have you tried using the overload with the namespaces parameter?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文