title: Asp.Net Core policy based authorization ends with 401 Unauthorized
body: <p>I am working on setting up a skeleton of custom policy based authorization which will have a set of business rules to authorized the currently logged on user. But, currently the skeleton always ends up with 401 <code>Unauthorized</code>.</p>
  
  <p>Here is my code,</p>
  
  <pre><code>public class MyAuthorizationRequirement : IAuthorizationRequirement
  {
      public MyAuthorizationRequirement()
      {       
      }
  }
  
  public class MyAuthorizationHandler : AuthorizationHandler&lt;MyAuthorizationRequirement&gt;
  {
      public MyAuthorizationHandler()
      {
      }
  
      protected override void Handle(AuthorizationContext context, MyAuthorizationRequirement requirement)
      {
          context.Succeed(requirement);
      }
  }
  </code></pre>
  
  <p>And following in the <code>Startup.cs</code></p>
  
  <pre><code>    public void ConfigureServices(IServiceCollection services)
      {
          services.AddSingleton&lt;IAuthorizationHandler, MyAuthorizationHandler&gt;()
          .AddAuthorization(options =&gt;
          {
              options.AddPolicy("MyAuthorization",
                                  policy =&gt; policy.Requirements.Add(new MyAuthorizationRequirement()));
          });
      }
  </code></pre>
  
  <p>And this is how I use it in my <code>HomeController</code> (MVC 6)</p>
  
  <pre><code>[Authorize(Policy = "MyAuthorization")]
  public class HomeController : Controller
  {
      public IActionResult Index()
      {
          return View();
      }
  }
  </code></pre>
  
  <p>When I don't put the <code>Authorize</code> attribute, the Index view renders fine. But, when I include the <code>Authorize</code> attribute, I just receive the blank view. And when I check the developer tools (Network) I get the following behind the scene details.</p>
  
  <pre><code>Request URL:http://localhost:51129/
  Request Method:GET
  Status Code:401 Unauthorized
  Remote Address:[::1]:51129
  </code></pre>
  
  <p>The breakpoints to the constructors of my requirement and handler classes are invoked, but the breakpoints to the <code>Handle</code> method of <code>Handler</code> class, and <code>Index</code> method of <code>Controller</code> class never get invoked.</p>