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
You can write a generic pattern for areas using MapControllerRoute()
:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);
endpoints.MapDefaultControllerRoute();
});
Then the area controllers just need the Area
attribute:
[Area("AreaName")]
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
}