title: Get Controller and Action Name whern creating Custom Authorization Policy in .NET Core 6 using IHttpContextAccessor
body: <p>I, am trying to configure a custom Authorization policy in .NET Core 6 with the following logic in a Handler:</p>
  <ol>
  <li>Get Controller Name and Get Controller Action which user is trying to access</li>
  <li>If Claim.Type = Controller Name and Value = Controller Action then grant access.</li>
  </ol>
  <p>I, am trying to access the Controller Name and Action using IHttpContextAccessor injected into the Handler class. How can I get the controller name and action method name? I found several articles mentioning how to do so in previous versions of .NET Core. But those do not work on .NET 6. It always provides NULL value</p>
  <p><strong>Current AccessHandler (Previous Versions of .NET)</strong></p>
  <pre><code>using Microsoft.AspNetCore.Authorization;
  
  namespace myApp.Security
  {
      public class AccessHandler : AuthorizationHandler&lt;AccessRequirement&gt;
      {
          private readonly IHttpContextAccessor httpContextAccessor;
  
          public AccessHandler(IHttpContextAccessor httpContextAccessor)
          {
              this.httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
          }
          protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, AccessRequirement requirement)
          {
                 
              string? controllerName = httpContextAccessor.HttpContext?.Request.Query[&quot;controller&quot;].ToString();
  
              string? actionName = httpContextAccessor.HttpContext?.Request.Query[&quot;action&quot;].ToString();
  
              if (controllerName != null &amp;&amp; actionName != null)
              {
                  if (context.User.HasClaim(claim =&gt; claim.Type == controllerName &amp;&amp; claim.Value == actionName))
                  {
                      context.Succeed(requirement);
                  }
              }
  
              return Task.CompletedTask;
          }
      }
  }
  </code></pre>