如何覆盖 .ASP.NET Core 5 中的路由?
How to override route in .ASP.NET Core 5?
我想覆盖 ASP.NET Core 5
中的路由
我试过这个,但没用
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", });
创建具有高不同显示顺序的相同路线对我有用
好在插入同名新路由时不会抛出任何异常
public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
{
endpointRouteBuilder.MapControllerRoute("NewCheckout", "onepagecheckout",
new { controller = "NewCheckout", action = "OnePageCheckout" });
}
return string.Empty;
}
public int Priority
{
get
{
return 100;
}
}
}
我想覆盖 ASP.NET Core 5
中的路由我试过这个,但没用
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", });
创建具有高不同显示顺序的相同路线对我有用
好在插入同名新路由时不会抛出任何异常
public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
{
endpointRouteBuilder.MapControllerRoute("NewCheckout", "onepagecheckout",
new { controller = "NewCheckout", action = "OnePageCheckout" });
}
return string.Empty;
}
public int Priority
{
get
{
return 100;
}
}
}