I'm trying to debug an issue with routes where I'm not sure what url an external app has to hit to trigger my controllers correctly. I just want to print them all out.
I found Get all registered routes in ASP.NET Core but none of the answers seem to work in Asp.net Core 3.0
I also found https://www.nuget.org/packages/AspNetCore.RouteAnalyzer, but it's for Core 2.0
I just want to print them all out.
So, I guess this is for debugging purposes?
In that case, this will get you started:
public HomeController(IActionDescriptorCollectionProvider provider)
{
this.provider = provider;
}
public IActionResult Index()
{
var urls = this.provider.ActionDescriptors.Items
.Select(descriptor => '/' + string.Join('/', descriptor.RouteValues.Values
.Where(v => v != null)
.Select(c => c.ToLower())
.Reverse()))
.Distinct()
.ToList();
return Ok(urls);
}
This will return response in the following format:
[
"/post/delete",
"/users/index/administration",
"/users/details/administration",
]
If you need more information, the IActionDescriptorCollectionProvider
has plenty of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With