I'm Implementing a custom PermissionValueProvider and it should compare user's role with an URL query parameter or a field in the body of HTTP post request and some data in database. so i need HttpRequest object in method CheckAsync. Is there a way to get that?
``` C#
public class FilteredRolePermissionValueProvider : PermissionValueProvider
{
public FilteredRolePermissionValueProvider(IPermissionStore permissionStore) : base(permissionStore)
{
}
public override string Name => "FilteredRole";
public override Task<PermissionGrantResult> CheckAsync(PermissionValueCheckContext context)
{
///
/// I have an entity called MPE and I need to check the role of the user if it belongs to
/// mpe_id given in the url or body of http request or not
/// (Actually I'm trying to relate roles to a MPE object)
///
}
}
```
Try to inject IHttpContextAccessor(https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-context?view=aspnetcore-3.1#use-httpcontext-from-custom-components).
Note that not all contexts can get HttpContext.
Most helpful comment
Try to inject
IHttpContextAccessor(https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-context?view=aspnetcore-3.1#use-httpcontext-from-custom-components).Note that not all contexts can get HttpContext.