Check user roles from Application Service
Asked Answered
L

1

5

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?

Lovering answered 25/10, 2017 at 10:50 Comment(0)
S
14

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).

Sour answered 25/10, 2017 at 13:38 Comment(3)
OMG ... yes, it's right! I had already injected the UserManager but i didn't see the existence of IsInRole method TnxLovering
maybe the name of the method change to IsInRoleAsyncWham
What about getting ALL the roles for a user, given the userId?Calk

© 2022 - 2024 — McMap. All rights reserved.