问题
I am trying to migrate from .net core 2.2 routing to endpoint routing in asp.net core 3 with following route in startup
My .net core 2.2 route were
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "AppArea",
template: "{area:exists}/{controller=Home}/{did?}/{action=Index}/{id?}");
.net core 3 route
app.UseEndpoints(routes =>
{
routes.MapControllerRoute(
name:"default",
pattern:"{controller=Home}/{action=Index}/{id?}");
routes.MapAreaControllerRoute(
name: "areas",
areaName: "myarea",
pattern: "{area:exists}/{controller=Home}/{did?}/{action=Index}/{id?}");
routes.MapRazorPages();
});
My issue is in .net core 2.2 above configuration map multiple areas such as area1
area2
etc. but in .net core it only works if i give hard code area name not the dynamic areaname
回答1:
In order to not specify any area name, you can use this.
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "areas",
pattern: "{area}/{controller}/{did?}/{action=Index}/{id?}");
});
来源:https://stackoverflow.com/questions/59334447/endpoint-routing-net-core-3-multiple-areas