本文介绍了端点路由.net核心3多个区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从.net core 2.2路由迁移到asp.net core 3中的终结点路由,并在启动时遵循以下路由
I am trying to migrate from .net core 2.2 routing to endpoint routing in asp.net core 3 with following route in startup
我的.net核心2.2路由是
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核心3路由
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();
});
我的问题是在.net core 2.2以上的配置映射中,例如area1
area2
等多个区域.但是在.net core中,它仅在我给出硬代码区域名称而不是动态区域名称的情况下有效
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
推荐答案
为了不指定任何区域名称,可以使用此名称.
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?}");
});
这篇关于端点路由.net核心3多个区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!