title: Running code before an MVC action in controller with [AllowAnonymous] executes
body: <p>I have a bunch of controllers that have the [AllowAnonymous] attribute in class-level scope. I need to check a few things before any of the actions in such controllers executes. For example, I might do something like this:</p>
  
  <pre><code>[AllowAnonymous]
  public class MyController : Controller
  {
      [HttpGet]
      public ActionResult Index()
      {
          // do some preliminary work
  
          // run action-specific code
      }
  }
  </code></pre>
  
  <p>Because I have many such controllers and actions, copy-pasting the same code is a tedious process. Is there a way to execute this preliminary code for every anonymous action in a much simpler way?</p>