Jimy Weiss
Jimy Weiss

Reputation: 678

ActionExecutingContext ActionDescriptor doesn't contain ActionName and MethodInfo

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.

enter image description here enter image description here

Upvotes: 21

Views: 6386

Answers (1)

CodingYoshi
CodingYoshi

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

Related Questions