我是 .NET Core 的新手。我想获取 ASP.NET Core 中所有已注册路由的列表。在 ASP.NET MVC 中,我们有路由表System.Web.Routing
,ASP.NET Core 中有类似的东西吗?我想在我的控制器操作中获取路由列表。
我创建了 NuGet 包“AspNetCore.RouteAnalyzer”,它提供了获取所有路由信息的功能。
-
NuGet 画廊 | AspNetCore.RouteAnalyzer... NuGet Gallery 上的包
-
kobake/AspNetCore.RouteAnalyzer... 使用指南
如果你愿意的话可以尝试一下。
Usage
包管理器控制台
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
....
});
}
Browse
Run project and you can access the url /routes
to view all route information of your project.
![](https://raw.githubusercontent.com/kobake/AspNetCore.RouteAnalyzer/master/screenshots/screenshot.png)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)