Abp: how can I get HttpRequest Object in a class derived from PermissionValueProvider?

Created on 8 Feb 2020  路  1Comment  路  Source: abpframework/abp

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)
      ///
    }
}

```

question

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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leonkosak picture leonkosak  路  3Comments

hikalkan picture hikalkan  路  3Comments

ugurozturk picture ugurozturk  路  3Comments

hikalkan picture hikalkan  路  3Comments

hikalkan picture hikalkan  路  3Comments