Middleware for filtering asp.net core REST methods
<p>I have a .net core application with several REST operations (see code below), similar to the following:</p>

<pre><code>
    namespace Controllers
    {
      [Route("system")]
      public class SystemController : Controller
      {
        // This is a public access method
        [HttpGet("dictionaries/{name}")]
        public List GetDictionary(HttpRequestMessage requestMsg, string name)
        {
          // etc
        }

        // This function shall be accessible only by an admin role
        <b>[AdminRole]</b>
        [HttpPost("dictionaries/{name}")]
        public IActionResult PostDictionary(HttpRequestMessage requestMsg, string name)
        {
          // etc
        }
      }
    }
</code></pre>

<p>I want to flag some operations to be accessible only by certain roles (i.e. admin). An elegant way to do it is using attributes.</p>

<p>Now I want to determine what would be the correct <code>Middleware</code> implementation for <strong>trapping the C# method to be invoked according to the URL</strong>, and fetch the role attribute (if any) by using reflection, so I can block unauthorized calls.</p>

<p>Please advice.</p>