我是 .NET Core 的新手。我想获取 ASP.NET Core 中所有已注册路由的列表。在 ASP.NET MVC 中,我们在 System.Web.Routing
中有路由表,在 ASP.NET Core 中是否有等效的东西?我想在我的 Controller 操作中获取路由列表。
最佳答案
我创建了 NuGet 包“AspNetCore.RouteAnalyzer”,它提供了获取所有路由信息的功能。
- NuGet Gallery | AspNetCore.RouteAnalyzer ... NuGet Gallery 上的包
- kobake/AspNetCore.RouteAnalyzer ... 使用指南
如果你愿意,试试吧。
用法
包管理器控制台
PM> Install-Package AspNetCore.RouteAnalyzer
启动.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
查看项目的所有路由信息。
关于c# - 获取 ASP.NET Core 中所有已注册的路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41908957/