简体   繁体   English

如何覆盖路由 in.ASP.NET Core 5?

[英]How to override route in .ASP.NET Core 5?

I want to override route in ASP.NET Core 5我想覆盖 ASP.NET Core 5 中的路由

I tried this one but it is not working我试过这个,但它不工作

var lastExistingRoute= routeBuilder.Routes.FirstOrDefault(x => ((Route)x).Name == "HomePage");
            routeBuilder.Routes.Remove(lastExistingRoute);
            routeBuilder.MapRoute("HomePage", "",
                new { controller = "CustomPage", action = "Homepage", });


  var lastDownloadRoute=routeBuilder.Routes.FirstOrDefault(x => ((Route)x).Name == "GetDownload");
            routeBuilder.Routes.Remove(lastDownloadRoute);
            routeBuilder.MapRoute("GetDownload", "download/getdownload/{guid}/{agree?}",
                new { controller = "AzTechProduct", action = "GetPayed", });

Created same route with high different display order is worked for me创建具有高不同显示顺序的相同路线对我有用

And good this is it not throwing any exception on inserting new route with the same name好在插入同名的新路由时不会抛出任何异常

 public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
        {
           
            endpointRouteBuilder.MapControllerRoute("NewCheckout", "onepagecheckout",
                      new { controller = "NewCheckout", action = "OnePageCheckout" });
                    
        }

       
            return string.Empty;
        }

    public int Priority
        {
            get
            {
                return 100;
            }
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM