asp.net-coreroutesasp.net-core-5.0asp.net-core-routing

How to override route in .ASP.NET Core 5?


I want to override route in 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", });

Solution

  • 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;
                }
            }
        }