Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Authorization can be done based on user roles.</p> <p>While creating authorization, we always keep in mind that it should dynamic. New user group will come having different permissions. So what I am suggesting is to have the information in a database. </p> <p>For eg</p> <p>User Group Admin Normal Users Resturants</p> <p>Roles All Privileage Basic Privilage Intermediate Privileage</p> <p>You need to use action filters to obtain this. <a href="http://msdn.microsoft.com/en-us/library/dd410209(v=vs.100).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/dd410209(v=vs.100).aspx</a></p> <p>Next we need to assign privilages to each roles</p> <p>All Privileage - addUser, addResturant, etc (you can use friendly names for administrative purpose. It can be displayed in UI, but we need to store controller name and action name.In case of addUser , friendly name will be Add User and we store like below</p> <pre><code>ActionsTable (actionId, friendName, Controller, Action) 1 -Add User - Users - Add RolesActionMapTable (roleId, actionID) 1-1 RolesTable (RoleId,Role Name,Desc) 1-AllPrivileage GroupsTable (GroupId, GroupName) 1-Admin GroupRoleMap (groupId, roleID) 1-1 </code></pre> <p>Create a custom Autorize attriute by inheriting authorize attribute and apply it as filter for all methods. There is an overloaded function, and you can check the user is allowed to access that action there. Hence you can block the unauthorized access.</p> <p><strong>EDIT</strong></p> <p>From the route data we can identify the controller and action, so we can query db using the userID, controller and action that whether is allowed or you can get the users group and check that it was included the permission to access this</p> <p><strong>EDIT 2</strong></p> <pre><code>public class CustomAuthorizeAttribute: AuthorizeAttribute { protected virtual bool AuthorizeCore( HttpContextBase httpContext) { // 1.Httpcontext can gives you the controller and action // 2. retrive the group of user and check the user is allowed to execute this action // 3. if allowed, then return true else return false. // 4. You can redirect to another page saying you are not allowed to access this action } ) } //In controller public class EmployeeController: Controller { [CustomAuthorize] public Create() { } } </code></pre> <p>Hope this helps</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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