I want to create a custom authorization attribute to verify the path and URL.
I found a way to do this in Asp.Net Core using an authorization-based policy, but I tried to implement it, but I cannot get the HttpContext with the incoming URL.
AuthorizationHandlerContext does not have access to HttpContext.
How can I get the current HttpContext with a url? Can this be done, or using another method?
I tried this code to create a custom policy:
public class RoleUrlValidationHandler : AuthorizationHandler<RoleUrlValidationRequirement>
{
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, RoleUrlValidationRequirement requirement)
{
var path =
var pathPart = path.Split('/');
var clientId = pathPart[3];
if (context.User.IsInRole(clientId))
{
context.Succeed(requirement);
}
return Task.CompletedTask;
}
}
I want to create the following:
[Authorize(Policy="RoleUrlValidation")]
public class PostsController : Controller
{
public ActionResult Get()
{
}
}
Jenan source
share