Endpoint Routing .net core 3-Multiple Areas

流过昼夜 提交于 2020-01-15 03:41:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!