title: Sending method parameters to action filter through the constructor
body: <p>I'm building a website in ASP.NET Core and I just started setting up some filters to control the access to certain methods, and one of the criteria for some methods is the Referer header of the request.</p>
  
  <p>I'd like to send the valid URL for the Referer to the action filter as an argument through the constructor.</p>
  
  <p>I created the following filter:</p>
  
  <pre><code>public class RefererFilter : ActionFilterAttribute
  {
      private List&lt;string&gt; referers;
  
      public RefererFilter(params string[] _referers)
      {
          referers = new List&lt;string&gt;(_referers);
      }
  
      public override void OnActionExecuting(ActionExecutingContext context)
      {
          bool valid = false;
  
          foreach (string referer in referers)
          {
              if (context.HttpContext.Request.Headers["Referer"].ToString() == ("https://" + context.HttpContext.Request.Host.Value + referer))
              {
                  valid = true;
                  break;
              }
          }
  
          if (!valid)
              context.Result = new StatusCodeResult(403);
  
          base.OnActionExecuting(context);
      }
  }
  </code></pre>
  
  <p>And I'd like to use it like this:</p>
  
  <pre><code>[RefererFilter("/Users/ChangePassword/" + id)]
  public IActionResult PasswordChanged(int id)
  {
      return View();
  }
  </code></pre>
  
  <p>The problem is that the variable "id" doesn't exist in the filter call.</p>
  
  <p>I know there are other ways to do this by getting the attributes from inside the action filter by knowing their name in the method, but that would force me to create various filters because URLs don't all follow the same structure.</p>
  
  <p>Is there any way this can be done?</p>