0

I am new to MVC ASP.Net. I need to create two admin roles in my MVC 5 EF 6 project. First role is Admin Role, which can able to access whole records. and another role is only to access the specific department records which the logged-in user belongs to. Please suggest the best way to accomplish this?

GhitaB
  • 3,275
  • 3
  • 33
  • 62
Kesi
  • 11
  • 3

1 Answers1

0

In your database create a user table (i.e. named Users). Then insert staff details such as StaffNumber, WindowsLogon (if this is applicable), ForeName, Surname and AccessType (check the diagram below). Under AccessType declare your roles (i.e. AdminRole and AdminRole2). This allows your application to detect who the user is and what Admin Role they are.

StaffNumber  WindowsLogon  Forename Surename  AccessType       
12345        kesi_k        kesi     kesi      AdminRole

In your controller is where you need to write your code for this all to take effect.

An alternative, depending on how many users you have, would be to get your system administrator to create ative directory groups, in your case you would need two. Then place users into one of the two groups. In your controller you would then make use of User.IsInRole in order to determine which user should see what you want. Hopefully the below links will be of some use to you.

SO

Custom Role Providers

Working with Roles in ASP.NET Identity for MVC

Membership and Authorization

Community
  • 1
  • 1
Scanner
  • 597
  • 1
  • 9
  • 19