METHOD
AuthorizationHandlerContext.Fail
Marks authorization as failed even if other handlers satisfy requirements. Use for explicit hard-deny rules; simply not satisfying a requirement can allow another applicable handler to satisfy it.
Formal Syntax & Structure
csharp syntaxcsharp
context.Fail();Working Example
Example Snippetcsharp
using System;using System.Security.Claims;using System.Linq;using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Authorization.Infrastructure;var r = new DenyAnonymousAuthorizationRequirement();var ctx = new AuthorizationHandlerContext(new[]{r},new ClaimsPrincipal(),null);ctx.Fail();Console.WriteLine(ctx.HasSucceeded); // False