.net core 2.2(MVC)中每个区域都需要一个默认页面。这意味着,如果有人键入例如“ https://url/admin”(其中admin是区域),则他将被路由说“ https://url/admin/user/index”。我想在每个领域都做到这一点。
在app.UseMvc(routes => ...中设置第二个默认页面区域给我一个错误。
答案 0 :(得分:2)
只需更改区域路由的默认控制器和动作,如
app.UseMvc(routes =>
{
routes.MapRoute(
name: "areas",
template: "{area:exists}/{controller=User}/{action=Index}/{id?}"
);
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
更新: 如果要将不同区域路由到不同的默认页面,则可以分别为这两个区域设置路由:
app.UseMvc(routes =>
{
routes.MapAreaRoute(
name: "AdminRoute",
areaName: "Admin",
template: "Admin/{controller=News}/{action=Index}/{id?}");
routes.MapAreaRoute(
name: "ManagementRoute",
areaName: "Management",
template: "Management/{controller=User}/{action=Detail}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});