Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 896
Jimy Weiss Avatar asked Jun 23 '17 22:06

Jimy Weiss


1 Answers

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;
like image 53
CodingYoshi Avatar answered Sep 29 '22 23:09

CodingYoshi