I am trying to define a MapAreaControllerRoute()
that routes to multiple Areas. In ASP.NET Core 3.0, however, there is the areaName:
parameter that needs to be set, thus restricting each route to a single area. I don't understand how I can use one route that will work for multiple Areas.
I have read through many issues here on Stack Overflow, but it seems that this is a new requirement in ASP.NET Core 3.0. In ASP.NET Core <= 2.2 you could create a MapRoute()
without defining a set areaName
.
As it is now, in my Startup.cs
, I define my endpoints as:
app.UseEndpoints(endpoints =>
{
endpoints.MapAreaControllerRoute(
name: "Area1",
areaName: "Area1",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);
endpoints.MapAreaControllerRoute(
name: "Area2",
areaName: "Area2",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
Surely, there must be a way to define a single route to cover all Areas?