Consider the following code:
public class MyAttribute : Attribute { }
[MyAttribute]
public class MyControlller : Controller
{
//...
}
Now that I have a Global Action Filter
which gets me an ActionExecutingContext
object.
My question is, here, how do I check if the requested Controller
has been adorned with my custom Attribute
.
Try
actionExecutingContextInstance.Controller.GetType().GetCustomAttributes(typeof(MyAttribute), false).Length > 0)
Or
actionExecutingContextInstance.ActionDescriptor.GetCustomAttributes(typeof(MyAttribute), false).Length > 0)
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