在.net core3.1下路由的配置方式跟2.0时代已经有了区别不再采用routes.MapRoute的方式,改用endpoints.MapControllerRoute的方式
配置普通的路由如
endpoints.MapControllerRoute(name: "default",pattern: "{controller=Login}/{action=Index}/{id?}");endpoints.MapControllerRoute(name: "route_a",pattern: "{controller=Login}/{action=Index}/{ida?}/{idb?}");
配置区域路由如
//A.就是通过指定特定的域。这种方式的缺点就是,每次新增域,都要新增这样一个注册//endpoints.MapAreaControllerRoute(// name: "Areas","Admin",// pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");//endpoints.MapAreaControllerRoute(// name: "Areas_a", "Admin",// pattern: "{area:exists}/{controller=Home}/{action=Index}/{ida?}/{idb?}");//B.此方式推荐endpoints.MapControllerRoute(name: "Areas",pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");endpoints.MapControllerRoute(name: "Areas_a",pattern: "{area:exists}/{controller=Home}/{action=Index}/{ida?}/{idb?}");
有两种方式,建议采用方法B.