title: DotNet Core Custom Authorize Attribute using Route Params
body: <p>I googled this and nothing was found, so I would like to know from those who use DotNet Core for a longer time than myself.</p>
  <p>I am now to DotNet core. I am currently creating an App just for the sake of practicing. I noticed that in most of my Apis' Actions, I am verifying the passed in UserId against claims NameIdentifier (that is the logged in user id).</p>
  <p>I am doing like so:</p>
  <pre><code>        if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
          {
              return Unauthorized();
          }
  </code></pre>
  <p>But now thinking, it is getting a bit too repetitive. Is there a way of using an Attribute instead?</p>
  <p>Something like:</p>
  <pre><code>    [AuthorizeUser(UserId = userid)]
      [HttpGet]
      public async Task&lt;IActionResult&gt; GetSomething(int userId)
      {
              //Custom code ...
      }
  </code></pre>
  <p>And then create my Authorize Attribute:</p>
  <pre><code>public class AuthorizeUser : AuthorizeAttribute, IAuthorizationFilter
  {
      public AuthorizeUser(params string[] args)
      {
          Args = args;
      }
  
      public string[] Args { get; }
  
      public void OnAuthorization(AuthorizationFilterContext context)
      {
          //Custom code ...
      }
  }
  </code></pre>
  <p>This way I would check for the user id passed in the <strong>&quot;api/user/{userId}&quot;</strong> in a single place for all my Actions.</p>
  <p>Or there is another way of making my code look nicer and with less copy and paste?</p>
  <p>Thank you in advance.</p>