How to get Action and Controller name in ASP.Net Core MVC app?

asp.net-core, asp.net-core-1.0, asp.net-core-mvc, c#

Solution

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`.

Problem

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.. ```

Original source