title: How to read action method's attributes in ASP.NET Core MVC?
body: <p>Based on <a href="https://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=98" rel="noreferrer">this article</a> I'm trying to create an <code>IActionFilter</code> implementation for ASP.NET Core that can process attributes that are marked on the controller and the controller's action. Although reading the controller's attributes is easy, I'm unable to find a way to read the attributes defined on the action method.</p>
  
  <p>Here's the code I have right now:</p>
  
  <pre><code>public sealed class ActionFilterDispatcher : IActionFilter
  {
      private readonly Func&lt;Type, IEnumerable&gt; container;
  
      public ActionFilterDispatcher(Func&lt;Type, IEnumerable&gt; container)
      {
          this.container = container;
      }
  
      public void OnActionExecuting(ActionExecutingContext context)
      {
          var attributes = context.Controller.GetType().GetCustomAttributes(true);
  
          attributes = attributes.Append(/* how to read attributes from action method? */);
  
          foreach (var attribute in attributes)
          {
              Type filterType = typeof(IActionFilter&lt;&gt;).MakeGenericType(attribute.GetType());
              IEnumerable filters = this.container.Invoke(filterType);
  
              foreach (dynamic actionFilter in filters)
              {
                  actionFilter.OnActionExecuting((dynamic)attribute, context);
              }
          }
      }
  
      public void OnActionExecuted(ActionExecutedContext context)
      {
          throw new NotImplementedException();
      }
  }
  </code></pre>
  
  <p>My question is: how do I read the action method's attributes in ASP.NET Core MVC?</p>