获取 ASP.NET Core 中所有注册的路由 [英] Get all registered routes in ASP.NET Core

查看:73
本文介绍了获取 ASP.NET Core 中所有注册的路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 .NET Core 的新手.我想获取 ASP.NET Core 中所有注册路由的列表.在 ASP.NET MVC 中,我们在 System.Web.Routing 中有路由表,在 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.

推荐答案

我创建了 NuGet 包AspNetCore.RouteAnalyzer",该包提供了获取所有路由信息的功能.

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

  • NuGet Gallery | AspNetCore.RouteAnalyzer ... Package on NuGet Gallery
  • kobake/AspNetCore.RouteAnalyzer ... Usage guide

如果您愿意,可以尝试一下.

Try it if you'd like.

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
        ....
    });
}

浏览

运行项目,您可以访问url /routes 查看您项目的所有路由信息.

Browse

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

这篇关于获取 ASP.NET Core 中所有注册的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆