I am new to .NET Core. I want to get a list of all registered routes in ASP.NET Core. In ASP.NET MVC we had route table in System.Web.Routing, is there somethin
If you don't use MVC call GetRouteData().Routers.OfType for access to RouteCollection:
app.UseRouter(r => {
r.MapGet("getroutes", async context => {
var routes = context.GetRouteData().Routers.OfType().First();
await context.Response.WriteAsync("Total number of routes: " + routes.Count.ToString() + Environment.NewLine);
for (int i = 0; i < routes.Count; i++)
{
await context.Response.WriteAsync(routes[i].ToString() + Environment.NewLine);
}
});
// ...
// other routes
});
Make sure to call GetRouteData() inside route handler otherwise it returns null.