Reputation: 678
As you below can see, in my ActionFilter, I try to get the ActionName and the MethodInfo of the ActionExecutingContext.ActionDescriptor. But the compiler says that ActionDescriptor doesn't contain a definition for ActionName and MethodInfo. But if I debug the application, I can see, that the ActionDescriptor contains these properties (see pics below). I'm using ASP .NET Core and I have no idea, where the problem could be.
Upvotes: 21
Views: 6386
Reputation: 27019
You need to cast it to ControllerActionDescriptor since that class has the properties you need.
var descriptor = context.ActionDescriptor as ControllerActionDescriptor;
var actionName = descriptor.ActionName;
var methodInfo = descriptor.MethodInfo;
Upvotes: 38