Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net MVC role based access to controller
    primarykey
    data
    text
    <p>A lot of articles online on role based access speak of applying something like this to ensure role based access to a controller or action</p> <pre><code>[Authorize(Roles = "Admin, Manager")] public class SomeController : Controller { } </code></pre> <p>All this is fine, but now if I need to implement my own custom role based access wherein I have roles in a [RoleMaster] table and the roles assigned to a user from a [User] table in another table called [UserRoles]. In my code I will have a user object in session which will now have a Roles list in it</p> <pre><code>public class RegisteredUsers { //... other user properties public List&lt;UserRole&gt; Roles { get; set; } } public class UserRole { public string RoleID { get; set; } public string RoleName { get; set; } //... other properties } </code></pre> <p>Now how do I check for the UserRole.RoleName property in the Roles list in the RegisteredUsers object as matching against any of the values I have assigned to the Authorize attribute using : [Authorize(Roles = "Admin, Manager")]. In some case if the roles have either Admin or Manager they should get access. In some cases I will want them to have both Admin as well as Manager Role to get access. </p> <p>Also, in the future if new roles get added to the system will I need to rebuild and redeploy my application with all the Authorize attributes redone?</p> <p>I have not been able to find any clear example implementing the same, or perhaps I am not searching correctly. Please help me out in any way you can. Thanks for your time...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload