custom authorization policy with multiple requirements cannot be invoked when the controller action is applied

Because the place where MyCustomPolicyHandler is injected is misplaced. It needs to be placed outside of AddAuthorization.

services.AddAuthorization(options =>
{
     options.AddPolicy("MyCustomPolicy", policy =>
     {
         policy.Requirements.Add(new RequirementA());
         //...
     });          
});

services.AddScoped<IAuthorizationHandler, MyCustomPolicyHandler>();

Result: enter image description here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top