区域文件夹如下所示:
Areas
Admin
Controllers
UserController
BranchController
AdminHomeController
项目目录如下所示:
Controller
UserController
GetAllUsers
区域路线登记
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
new { controller = "Branch|AdminHome|User" }
);
}
项目路线登记
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "MyApp.Areas.Admin.Controllers" });
}
当我这样路由时:http://mydomain.com/User/GetAllUsers
我得到资源未找到错误(404)。将 UserController 添加到 Area 后出现此错误。
我该如何解决这个错误?
谢谢...