c# - 根据角色和某些条件在 mvc 视图中渲染特定部分
问题描述
I have a requirement to render 4 buttons (Add, Delete, Read, Update) in a view based on the following conditions:
i) Each user can have multiple roles.
ii) Each roles will have specific permissions for each pages.
以下是我设计的表格。
Table Page:
i) PageId
ii) Page Name
iii) Controller Name
iv) Action Name
Table Role
i) RoleId
ii) Role Name
Table UserRole
i) UserId
ii) RoleId
Table Permission
i) PermissionId
ii) RoleId
iii) PageId
iv) CanRead <--- Boolean
v) CanAdd <--- Boolean
vi) CanDelete <--- Boolean
vii) CanUpdate <--- Boolean
viii) Controller Name
ix) Action Name
UserId RoleId
-------------------- -----------
2 1
2 2
4 2
5 2
存储在 UserRole 表中的数据
Id RoleId PageId CanView CanInsert CanUpdate CanDelete
----------- ----------- ----------- ------- --------- --------- ---------
1 1 1 1 0 1 1
2 1 2 1 0 0 1
3 1 3 0 0 1 1
4 2 1 0 0 0 0
5 2 2 1 1 0 0
6 2 3 0 0 1 1
Data Stored in permission table.
例如:角色管理员可以在用户页面中拥有读取、删除、添加或更新的权限。同一个角色可能只是在员工页面中只有读取权限。无论用户在哪里浏览到某个页面,都应根据他为该特定页面设置的角色和权限来呈现 4 个按钮。此外,用户可以同时拥有管理员和用户角色。
我希望我是有道理的,并正确地传达了我的要求。
解决方案
推荐阅读
- sql-server - 在代码点火器 MSSQL 上使用连接删除返回错误
- javascript - 未使用 jquery 和 javascript 检查 CheckBox
- java - Weblogic 失败并出现错误:org.springframework.beans.factory.BeanCreationException:创建带有名称的 bean 时出错
- kubernetes - 没有可用于 Kubernetes 仪表板服务的端点
- sql - SQL 查询分组依据和排序依据
- html - 将 para 拆分为 6 列,并使用 css 将图像放在 3 列中
- java - 使用java在seleniumwebdriver中上传文件时如何处理(windows)打开按钮
- mysql - 连接来自旋转 mysql 的结果值
- sql - 同一列在 oracle db 中有两种不同的日期格式
- html - 响应式 CSS 网格(1 列移动设备、2 平板电脑、3 桌面)设置