title: AuthorizationPolicy set status code
body: <p>I have an <code>AuthorizationHandler</code> and I would like to return a custom statuscode ( or text ) right now I am just trying to make it return 429 ( which is for rate limit but that's not relevant )</p>
  
  <pre><code>public class ReCaptchaHandler : AuthorizationHandler&lt;ReCaptchaRequirement&gt;
  {
      private readonly ReCaptcha _reCaptcha;
      private readonly IHttpContextAccessor _accessor;
  
      public ReCaptchaHandler(ReCaptcha reCaptcha, IHttpContextAccessor accessor)
      {
          _reCaptcha = reCaptcha;
          _accessor = accessor;
      }
      protected override  Task HandleRequirementAsync(AuthorizationHandlerContext context,
          ReCaptchaRequirement requirement)
      {
  
          context.Fail();
          _accessor.HttpContext.Response.StatusCode = 429;
          return Task.CompletedTask;
      }
  }
  
  public class ReCaptchaRequirement :  IAuthorizationRequirement
  {
  }
  </code></pre>
  
  <p>as you can see, I am trying to set the status = 429 with <code>_accessor.HttpContext.Response.StatusCode = 429;</code></p>
  
  <p>I have tried using the http context from <code>var filterContext = context.Resource as AuthorizationFilterContext;</code> and then <code>filterContext.HttpContext</code></p>
  
  <p>I create my policy as follows </p>
  
  <pre><code>services.AddSingleton&lt;IAuthorizationHandler, ReCaptchaHandler&gt;();
  services.AddSingleton&lt;IHttpContextAccessor, HttpContextAccessor&gt;();
  services.AddAuthorization(options =&gt;
  {
      options.AddPolicy("ReCaptcha",
          policy =&gt; policy.Requirements.Add(new ReCaptchaRequirement()));
  });
  </code></pre>
  
  <p>The code runs and protects the route marked with <code>[Authorize(Policy = "ReCaptcha")]</code> but the status is always 400 unless I throw an exception. </p>