title: Passing values to Custom authorization policy ASP.net Core
body: <p>Hi I want to pass parameters to the custom policy in asp.net core. As i know so far i can only do</p>
  
  <pre><code>[Authorize(Policy="Over21")]
  My Action(){
  }
  </code></pre>
  
  <p>but i want to do </p>
  
  <pre><code>[Authorize(Policy="Over21",Para="AnotherValue")]
  My Action(){
      }
  </code></pre>
  
  <p>so i decided to extend Authorize attribute and then do this.</p>
  
  <pre><code>public class MyAuthorizationAttribute : AuthorizeAttribute
      {
          public string Permission;    
          public MyAuthorizationAttribute(string policy, string permission)
              : base(policy)
          {
              Permission = permission;
          } 
  
      }
  </code></pre>
  
  <p>Then do this</p>
  
  <pre><code>[MyAuthorization("MyPolicy","CanDoPermission")]
  My Action(){
      }
  </code></pre>
  
  <p>The custom authorization handler is still called when i debug and so now i want a way to get the permission property from the <code>AuthorizationHandlerContext context</code>. I realize that i can find this property when i drill down during debug</p>
  
  <pre><code>context-&gt;Resource-&gt;Filters
  </code></pre>
  
  <p>Among this list i find all objects of type AuthorizeFilter and further drill down to <code>AuthorizeData-&gt;Resultview</code> this also is a list that contains my  MyAuthorization object. I use a debut tool to do this but i dont know how to get MyAuthorization instance that applies to the specific action being called? </p>
  
  <p>This is the furthest i get.</p>
  
  <pre><code>var mvcContext = context.Resource as AuthorizationFilterContext;
  
              foreach (var filterMetadata in mvcContext.Filters)
              {
                  if (filterMetadata.GetType().Name != "AuthorizeFilter") continue;
  
                  var claimAttribute = filterMetadata as AuthorizeFilter;
                  if (claimAttribute != null)
                  {
                      var data = claimAttribute.AuthorizeData;
                  }
  </code></pre>
  
  <p>Am not sure what to do next to get this object. I am hoping there is an easier way to get these values from the context.</p>