Currently, permission design has plagued us for a long time. For MVC, I will use ActionFilter to expand our permission authentication. The following example is extracted from one of my course center projects, I hope that this will serve as an example for beginners.
Next we will first design the database layer for permission control.
Next I will introduce the description of each field in sequence.
RoleGroup permission group table this table mainly groups system permissions. Our users can directly assign this group with all the permissions of this group.
RoleID permission group ID Example: 01
RoleName permission group name example: System Administrator
RoleState group status (Enabled or not) Example: True
RoleGroupAppList table group permissions corresponding to the table this table mainly copies the detailed list of permissions corresponding to each permission Group
ID primary key example: 1
ID of the permission group corresponding to the RoleID: 01
Example of detailed permission group ID corresponding to SysAppID: 01
StartTime: the start date of the permission, for example,. The default attribute of this field is all, that is, the start date is not limited.
EndTime: end date of the permission, for example,. The default attribute of this field is all, that is, the end date is not limited.
SysAppCate table this table is mainly used to classify SysAppList detailed permission tables. When there are many permission pages, this table is mainly used for convenient management. Omitted
SysAppCateID: 01
SysAppCateName: News management
SysAppCateEName
SysAppList permission Details table this table is mainly responsible for the basic list of all Permissions
SysAppID permission ID Example: 01
SysAppCateID permission category ID Example: 01
SysAppName permission name example: News Addition
SysAppEName permission English name
Example of a Controller with SysAppController permissions: News
SysAppAction: Add Action. This permission is designed to restrict Action permissions.
IsView is visible for example: True this field is designed to facilitate background management and settings, because some actions do not have a View layer, such as Post, but we need to use it in the background permission management.
Now, the database creation part is here. Next I will introduce the logic part, which will involve the Repository mode, cache, and custom AuthorizeAttribute.