ASP.NET 权限框架?

发布于 2024-12-07 03:24:29 字数 1315 浏览 2 评论 0原文

问题

ASP.NET 没有将权限与角色关联的概念。

我的应用程序

当前的 Web 应用程序正在使用自定义用户成员资格和角色提供程序。该应用有 4 个角色:超级用户管理员校长教师。当用户登录时,他们会被重定向到相应的 UI。例如,管理员被重定向到管理界面,教师被重定向到教师界面。每个界面都有自己的母版页和aspx页面。新的要求是教师不再被允许查看特定信息或执行特定功能。信息可以是 gridview 控件中的一个字段或一行,它也可以是功能性的(例如,无法单击链接来打开弹出窗口,但仍然能够看到链接的文本)。其他角色也有特定的“许可”要求,但与教师完全不同。

建议的解决方案

创建一个数据库表来集中权限到角色的映射,如下所示:

CREATE TABLE [dbo].[PermissionToRole](
    [PermissionID] [int] IDENTITY(1,1) NOT NULL primary key,
    [Role] int NOT NULL,
    [Control] [varchar](50) NOT NULL,
    [ControlType] [varchar](50) NOT NULL,
    [Function] [varchar](50) NOT NULL,
    [Read] [bit] NULL,
    [Write] [bit] NULL,
    [Execute] [bit] NULL,
    [Delete] [bit] NULL
)

使用上面的链接示例,我们会得到类似:“teacher”, "labelName", "asp:label", "click", 1, 0, 0, 0 (可以读取链接,但 不是“执行”点击)

该计划是能够做一些事情:

  1. 使用权限将多个 aspx 和逻辑合并到单个页面 (aspx) 中。每次需要新角色时减少维护。
  2. 在所有级别(选项卡 -> 控制)控制角色(又名组)的权限。例如,使用此表来控制每个级别(选项卡、页面、控件)的控件的可见性。以及单独的功能(例如单击链接控件)
  3. 控制将哪些数据返回到 UI 以及允许哪些 CRUD 操作。

是否有 ASP.NET 框架可以做到这一点? 我很确定内容管理系统 (CMS) 可以做到这一点,但此应用程序不会使用 CMS :)。我真的想避免重新发明轮子。

谢谢!

Problem

ASP.NET has no concept of associating permissions to roles.

My app

Current web application is using custom user membership and role providers. The app has 4 roles: superuser, admin, principal, and teacher. When the user logs in, they are redirected to their appropriate UI. For example, admins are redirected to admin interface, teachers are redirected to teacher interface. Each interface has its own master page and aspx pages. A new requirement is that teachers are no longer allowed to view specific information or do specific functions. Information could be a field or a row in a gridview control, it could be functional as well (e.g. not able to click on a link to open a popup window, but still be able to see the link's text). Other roles also have need of specific "permission" requirements, but completely different than the teachers ones.

Proposed Solution

Create a database table to centralize mapping of permissionsToRoles like so:

CREATE TABLE [dbo].[PermissionToRole](
    [PermissionID] [int] IDENTITY(1,1) NOT NULL primary key,
    [Role] int NOT NULL,
    [Control] [varchar](50) NOT NULL,
    [ControlType] [varchar](50) NOT NULL,
    [Function] [varchar](50) NOT NULL,
    [Read] [bit] NULL,
    [Write] [bit] NULL,
    [Execute] [bit] NULL,
    [Delete] [bit] NULL
)

Using the link example above we would get something like: "teacher",
"labelName", "asp:label", "click", 1, 0, 0, 0 (can read the link but
not "execute" the click)

The plan is to be able to do a few things:

  1. Use permissions to consolidate multiple aspx and logic into a single page (aspx). To reduce maintenance every time a new role is needed.
  2. Control at a all levels (tab -> control) a roles' aka groups' permissions. E.g. use this table to control visibility of controls at every level (tab, page, control). As well as individual functionality (e.g. click on a link control)
  3. Control what data is returned to the UI and what CRUD operations are allowed.

Are there frameworks out there for ASP.NET that can do this already? I'm pretty sure Content Management Systems (CMS) can do this, but this app will not use a CMS :). I really want to avoid reinventing the wheel.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

墨离汐 2024-12-14 03:24:29

请参阅 AzMan。我有一种感觉,这就是你所寻求的。

使用 AzMan,您可以定义操作并检查用户是否有权在代码中执行操作。然后,您可以定义允许哪些角色执行哪些操作并将角色分配给用户 - 因为您检查的是操作而不是角色,如果您想引入新角色或在角色之间重新分配操作,则无需更改代码。

Look at AzMan. I have a feeling that it's what you seek.

With AzMan you define operations and check if user authorized to do an operation in code. You can then define which roles allowed to do which operations and assign roles to users -- because you're checking against operations, not roles, no code changes will be necessary if you want to introduce a new role or reassign operations between roles.

当爱已成负担 2024-12-14 03:24:29

决定尝试 NetSqlAzMan 因为:

  • 不是 COM,而是
  • 用于数据存储的 .NET 4 RDBMS
  • AOP(面向方面​​的编程)(可以使用属性而不是大量的 if/else 检查)
  • 低耦合
  • 处理角色权限场景
  • 免费

Decided on trying NetSqlAzMan because:

  • Not COM and IS .NET 4
  • RDBMS for Data Store
  • AOP (Aspect Oriented Programming) (Can use attributes instead of massive if/else checks)
  • Lously coupled
  • Handles Permissions to Roles scenarios
  • Free
向地狱狂奔 2024-12-14 03:24:29

事实上,ASP.net 成员资格控制 应该能够做到你想要什么。使用适当的模式设置数据库允许您使用大量的方法和对象来控制用户访问。就像 Luis 提到的那样,您可以访问某些角色的控制页面和文件夹,但如果您想根据用户的角色锁定单个功能,您可以使用 IsUserInRole() 方法。

如果您可以使用内置的、经过充分测试的流程。

In truth, the ASP.net membership controls ought to be able to do what you want. Setting up a database with the appropriate schema allows you to use a huge suite of methods and objects to control user access. Like Luis mentions, you can access control pages and folders to certain roles, but if you want to lock out individual functions based on a user's role, you can use the IsUserInRole() method.

There isn't a whole lot of point in reinventing the wheel if you can use a built-in, well-tested process.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文