获取ASP.NET Core中所有已注册的路由 [英] Get all registered routes in ASP.NET Core
本文介绍了获取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
根据需要尝试.
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屋!
查看全文