【发布时间】:2014-04-07 20:55:03
【问题描述】:
我有一个包含几个方面的 MVC 应用程序。每个区域,以及根,都有一个 HomeController。
/Home/Index
/Admin/Home/Index
/Content/Home/Index
所有这些都可以正常工作并正确确定要使用哪个家庭控制器。
我的问题是每个区域也有 ReportsController,但根没有。
/Admin/Reports/Index
/Content/Reports/Index
这两项工作都按预期工作,但我收到 URL /Reports/Index 的“找到与控制器匹配的多种类型”错误。它在默认路线上匹配,但溢出到区域。我的假设是它应该是 404,就像去一条从所有区域都丢失的路线一样。
我的路由配置如下:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Website.Controllers" }
);
context.MapRoute(
"Content",
"Content/{controller}/{action}/{id}",
new { action = "Index", controller = "Home", id = UrlParameter.Optional },
namespaces: new[] { "Website.Areas.Content.Controllers" }
);
context.MapRoute(
"Admin",
"Admin/{controller}/{action}/{id}",
new { action = "Index", controller = "Home", id = UrlParameter.Optional },
namespaces: new[] { "Website.Areas.Admin.Controllers" }
);
问题路由 (/Reports/Index) 在默认路由映射上匹配,但不仅限于 Website.Controllers 的定义命名空间,它还在这些区域中查找。相反,它应该将搜索限制在 Website.Controllers 并在没有找到 ReportsController 时返回 404。
【问题讨论】:
标签: asp.net asp.net-mvc routes asp.net-mvc-routing