How to get Action and Controller names in ASP.Net MVC Core RC1 Application in Startup.cs?
I want to create a middleware and log the information (I want to Log detailed response to my Database, so I need Action and Controller info.) after following code in configure method of startup.cs -
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=User}/{action=Index}/{id?}");
});
//Want to get Action and controller names here..
You'll want to inject the IActionDescriptorCollectionProvider service into your middleware. From that, you can use the property ActionDescriptors.Items to get a list of ActionDescriptor, which has all the route values for that action. If you cast that to ControllerActionDescriptor, you'll have access to ControllerName and ActionName.
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