I have an ASP.NET Web API project. Using reflection, how can I get the Http verb ([HttpGet]
in the example below) attribute which decorates my action methods?
[HttpGet]
public ActionResult Index(int id) { ... }
Assume that I have the above action method in my controller. So far, by using reflection I have been able to get a MethodInfo object of the Index
action method which i have stored in a variable called methodInfo
I tried to get the http verb using the following but it did not work - returns null:
var httpVerb = methodInfo.GetCustomAttributes(typeof (AcceptVerbsAttribute), false).Cast<AcceptVerbsAttribute>().SingleOrDefault();
Something I noticed:
My example above is from a ASP.NET Web API project I am working on.
It seems that the [HttpGet]
is a System.Web.Http.HttpGetAttribute
but in regular ASP.NET MVC projects the [HttpGet]
is a System.Web.Mvc.HttpGetAttribute