title: How do I get http verb attribute of an action using refection - ASP.NET Web API
body: <p>I have an ASP.NET Web API project. Using reflection, how can I get the Http verb (<code>[HttpGet]</code> in the example below) attribute which decorates my action methods?</p>
  
  <pre><code>[HttpGet]
  public ActionResult Index(int id) { ... }
  </code></pre>
  
  <p>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 <code>Index</code> action method which i have stored in a variable called <code>methodInfo</code></p>
  
  <p>I tried to get the http verb using the following but it did not work - returns null:</p>
  
  <pre><code>var httpVerb = methodInfo.GetCustomAttributes(typeof (AcceptVerbsAttribute), false).Cast&lt;AcceptVerbsAttribute&gt;().SingleOrDefault();
  </code></pre>
  
  <hr>
  
  <p>Something I noticed:</p>
  
  <p>My example above is from a ASP.NET Web API project I am working on.</p>
  
  <p>It seems that the <code>[HttpGet]</code> is a System.Web.Http.HttpGetAttribute </p>
  
  <p>but in regular ASP.NET MVC projects the <code>[HttpGet]</code> is a System.Web.Mvc.HttpGetAttribute</p>