3

i'm implementing Application Service that sends statistical data to home page (dashboard application page).

Based on User's Role (the service needs authentication) i would extract/aggregate data from database using WhereIf() based on is role

In particular if user is administrator, I will not apply a data extraction filter using WhereIf()

To do that i've injected IAbpSession inside service constructor to be able to give userid, but how can i ckeck if user is an administrator?

Saro
  • 131
  • 1
  • 7

1 Answers1

11

You can check if current user is an administrator by checking the associated roles of that user. You must inject the UserManager which has several methods for role checking. One of them is IsInRole(userId, roleName).

Richard Brink
  • 161
  • 1
  • 6
  • 1
    OMG ... yes, it's right! I had already injected the UserManager but i didn't see the existence of IsInRole method Tnx – Saro Oct 25 '17 at 14:41
  • maybe the name of the method change to IsInRoleAsync – D__ Feb 12 '20 at 20:04