title: How create custom authorization attribute for checking a role and url path in Asp.Net Core?
body: <p>I want to create a custom authorization attribute for checking the role and url path.</p>
  
  <p>I've find the way for doing it in the Asp.Net Core using the Policy-Based-Authorization but I've tried implement it but I can't get the HttpContext with incomming url.</p>
  
  <p><code>AuthorizationHandlerContext</code> hasn't access to HttpContext probable.</p>
  
  <p>How can I get current HttpContext with the url path? Is it possible to do that or with another way?</p>
  
  <p>I've tried this code for creating the custom Policy:</p>
  
  <pre><code>public class RoleUrlValidationHandler : AuthorizationHandler&lt;RoleUrlValidationRequirement&gt;
  {
      protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, RoleUrlValidationRequirement requirement)
      {           
          var path = //Here I need get current url path for example - /api/posts/4545411
          var pathPart = path.Split('/');
          var clientId = pathPart[3];
  
          if (context.User.IsInRole(clientId))
          {
              context.Succeed(requirement);
          }
  
          return Task.CompletedTask;
      }
  }
  </code></pre>
  
  <p>I want to create following:</p>
  
  <pre><code>[Authorize(Policy="RoleUrlValidation")] //Get ClientId from Url and check User's roles
  public class PostsController : Controller
  {
      public ActionResult Get()
      {
      }
  }
  </code></pre>