The ASP.NET Core article titled “Custom Policy-Based Authorization” sample code passes a AuthorizationContext parameter into HandleRequirementAsync() methods.
Will someone please clarify AuthorizationContext vs AuthorizationHandlerContext and how to implement?
The AuthorizationHandlerContext class is what the handler uses to mark whether requirements have been met: C# Copy. context.Succeed(requirement) The following code shows the simplified (and annotated with comments) default implementation of the authorization service: C# Copy.
By using Policy-based & Role-based Authorization process, we can provide access to particular area of application to the user based on the Role/Policy of the user.
Right-click on the solution and add a new class. Enter the class name and click on Add. Next Inherite Attribute, IAuthorizationFilter to CustomAuthorization class which has overridden the OnAuthorization method. The OnAuthorization Method has the AuthorizationFilterContext parameter.
It stores the request and response information, such as the properties of request, request-related services, and any data to/from the request or errors, if there are any. ASP.NET Core applications access the HTTPContext through the IHttpContextAccessor interface. The HttpContextAccessor class implements it.
It seems AuthorizationContext
is old name of AuthorizationHandlerContext
. You should use AuthorizationHandlerContext
. See https://github.com/aspnet/Security/pull/819
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With