我正在尝试定义一个MapAreaControllerRoute()
到多个区域的路由。但是,在 ASP.NET Core 3.0 中,有areaName:
一个需要设置的参数,因此将每个路由限制在一个区域内。我不明白如何使用一条适用于多个区域的路线。
我已经阅读了有关 Stack Overflow 的许多问题,但似乎这是 ASP.NET Core 3.0 中的一个新要求。在 ASP.NET Core <= 2.2 中,您可以在MapRoute()
不定义 set的情况下创建 a areaName
。
就像现在一样,在 my 中Startup.cs
,我将端点定义为:
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?}");
});
Run Code Online (Sandbox Code Playgroud)
当然,必须有一种方法来定义一条路线来覆盖所有区域?