0

Similar to Get all registered routes in ASP.NET Core, but for .NET Framework (classic).

How to do it in classic ASP.NET?

This will be useful to compare legacy WebAPI and .NET 6 API


FYI: If someone is looking for updated code for .NET 6, here it is: https://github.com/ardalis/AspNetCoreRouteDebugger/pull/13

Saibamen
  • 610
  • 3
  • 17
  • 43
  • https://learn.microsoft.com/en-us/dotnet/api/system.web.mvc.urlhelper.routecollection?view=aspnet-mvc-5.2 – GSerg Jan 19 '23 at 12:26
  • @GSerg: From `RouteCollection` (by using reflections) I can only get controllers info and API endpoints for actions decorated with `System.Web.Http.RouteAttribute`. So I'm missing 530 registered routes for `api/{controller}/{id}` and `api/{controller}/{action}/{id}` routing. How to get all registered routes, like in AspNetCoreRouteDebugger repository? – Saibamen Feb 02 '23 at 11:32
  • Why are you using reflection for a `public` `System.Web.Routing.RouteCollection RouteCollection`? – GSerg Feb 02 '23 at 12:30
  • Because `System.Web.Http.WebHost.Routing.HttpWebRoute` is internal, so you can't do `RouteTable.Routes.OfType().Select(x => (....))` – Saibamen Feb 02 '23 at 15:28
  • Why are you using `System.Web.Http.WebHost.Routing.HttpWebRoute` instead of `System.Web.Routing.RouteCollection`? – GSerg Feb 02 '23 at 16:37
  • I want to have all my actions URLs, HTTP methods, parameters and templates to compare it with .NET (Core) 6 routes. For .NET 6 I'm using this code: https://github.com/ardalis/AspNetCoreRouteDebugger/blob/master/SampleProject/Controllers/RoutesController.cs. `System.Web.Routing.RouteCollection` doesn't have this information – Saibamen Feb 03 '23 at 00:50

1 Answers1

0

Steeltoe provides a Mappings Actuator that should return this information with minimal setup effort and similar output for ASP.NET (in Steeltoe 2.x.x packages) and ASP.NET Core (also in Steeltoe 2.x but you might want to use a newer 3.x package version).

Assuming you just want the code, I think what you're looking for should be in this file, notably var routeCollection = RouteTable.Routes; and the method AddRouteMappingsDescriptions

Tim
  • 2,587
  • 13
  • 18