How can I access current HttpContext to check for route and parameters inside AuthorizationHandlerContext of Custom Policy-Based Authorization inside ASP.NET Core 2?
Ref example: Custom Policy-Based Authorization
How can I access current HttpContext to check for route and parameters inside AuthorizationHandlerContext of Custom Policy-Based Authorization inside ASP.NET Core 2?
Ref example: Custom Policy-Based Authorization
Without injecting, simple solution!
You can inject an
IHttpContextAccessor
into yourAuthorizationHandler
s constructor.e.g.
You should inject an instance of an IHttpContextAccessor into your
AuthorizationHandler
.In the context of your example, this may look like the following:
You may need to register this in your DI setup (if one of your dependencies has not already), as follows: