title: How to pass a parameter to IActionFilter attribute?
body: <p>I'm trying to create my custom attribute using <code>IActionFilter</code>:</p>
  
  <p>Attribute:</p>
  
  <pre><code>public class MyAuthorize : TypeFilterAttribute
  {
      public int Id { get; set; }
  
      public MyAuthorize() : base(typeof(MyAuthorizeImplement))
      {
          Arguments = new object[] { Id };
      }
  
      private class MyAuthorizeImplement : IActionFilter
      {
          private readonly int _id;
  
          public MyAuthorizeImplement(int id)
          {
              _id = id;
          }
  
          public void OnActionExecuted(ActionExecutedContext context)
          {                
          }
  
          public void OnActionExecuting(ActionExecutingContext context)
          {
              context.Result = new ContentResult
              {
                  Content = $"Id: {_id}"
              };
          }
      }
  }
  </code></pre>
  
  <p>Action:</p>
  
  <pre><code>public class HomeController : Controller
  {
      [MyAuthorize(Id = 1)]
      public IActionResult Index()
      {
          return View();
      }
  }
  </code></pre>
  
  <p>Result content:</p>
  
  <blockquote>
    <p>Id: 0</p>
  </blockquote>
  
  <p>I've tried many times with the difference <code>Id</code> values, but <code>_id</code> is still <code>0</code> as default. Then I've tried to change the value types of <code>Id</code>, <code>id</code> and <code>_id</code> from <code>int</code> to <code>string</code> and pass some value but it's still <code>null</code>:</p>
  
  <pre><code>[MyAuthorize(Id = "abc")]
  </code></pre>
  
  <p>Do I miss something? Thank you!</p>
  
  <p>P/S: I also tried this way, it worked but I don't want to use it:</p>
  
  <p>Inside the constructor, tried to use <code>id</code> as a parameter instead of a property:</p>
  
  <pre><code>// public int Id { get; set; }
  
  public MyAuthorize(int id) : base(typeof(MyAuthorizeImplement))
  {
      Arguments = new object[] { id };
  }
  </code></pre>
  
  <p>Action:</p>
  
  <pre><code>public class HomeController : Controller
  {
      [MyAuthorize(id: 1)]
      public IActionResult Index()
      {
          return View();
      }
  }
  </code></pre>
  
  <p>Result content:</p>
  
  <blockquote>
    <p>Id: 1</p>
  </blockquote>
  
  <p>In the first case, the constructor doesn't require any parameter, it's an option but in the second it does. That's why I don't want to use it.</p>
  
  <p>When I need some <code>rule</code> (as <code>Id</code>, <code>Roles</code>, <code>Name</code>...), I can pass it. Otherwise, leave it empty. Just like <code>Authorize</code> attribute:</p>
  
  <pre><code>[Authorize] -&gt; All login user can assign
  [Authorize(Roles = "Administrator")] -&gt; Only user with this role can assign
  </code></pre>