Search code examples
aspnetboilerplateasp.net-boilerplate

Check user roles from Application Service


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?


Solution

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