Search code examples
c#asp.net-core

Get all registered routes in ASP.NET Core


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 something equivalent in ASP.NET Core? I want to get the routes list in my Controller Action.


Solution

  • I've created the NuGet package "AspNetCore.RouteAnalyzer" that provides a feature to get all route information.

    Try it if you'd like.

    Usage

    Package Manager Console

    PM> Install-Package AspNetCore.RouteAnalyzer
    

    Startup.cs

    using AspNetCore.RouteAnalyzer; // Add
    .....
    public void ConfigureServices(IServiceCollection services)
    {
        ....
        services.AddRouteAnalyzer(); // Add
    }
    
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        ....
        app.UseMvc(routes =>
        {
            routes.MapRouteAnalyzer("/routes"); // Add
            ....
        });
    }
    

    Browse

    Run project and you can access the url /routes to view all route information of your project.