“角色管理”与“用户管理”相比在 ASP.NET 中

发布于 2024-11-16 02:29:33 字数 416 浏览 2 评论 0原文

问题 1

我熟悉角色管理,特定角色中的特定成员可以执行此操作并在功能上访问此管理。我需要做的是管理单个用户,而不是他所在的角色。

例如,假设我创建一个名为“销售”的角色。我设置了销售人员可以做什么的角色权限。现在我想检查个人用户。例如,如果这是“john”,我想向他显示仅他创建的记录。如果他是彼得,我只想向他展示他创建的记录,而不是约翰或其他销售人员创建的记录。

ASP.NET中有一个叫做“用户管理”的东西可供我们使用吗?如果不是我们必须自己创建它,我相信与 ASP.NET“角色管理”的集成不会那么顺利。


Question No 2.

我正在使用用户登录控件。我想此时创建一​​个会话,以便我可以跟踪哪个用户登录,这样我就可以向他显示仅与他相关的记录。我怎样才能做到这一点?

Question No 1

I am familiar with role management, a particular member in a particular role can do this and access this functionally. What I need to do is Manage individual user, not the role he is in.

For example, lets say I create a role, called "Sales". I setup the role permission what the sales persons can do. Now i want to keep a check on individual user. For example if this is "john", i want to show him the records only he created. If his is peter, I want to show him only that records which he created, not by john or other sales people.

Is there a thing called "User Management" in ASP.NET that we can use? If not we have to create it ourselves and I believe the integration with ASP.NET "Role Management" will not be that smooth.


Question No 2.

I am using control for user login. I want to create a session at this time so I can keep track of which user is signed in so I can show him the records only pertaining to him. How can I do that?

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

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

发布评论

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

评论(4

中性美 2024-11-23 02:29:33

此时,您的第一个问题实际上并不是关于角色与用户管理(即:授权)。这是关于应用程序内的审计跟踪。

这样做的方法是捕获创建相关记录的用户的 ID,以便稍后您可以根据该 ID 进行过滤。

伪数据库结构

Table Sales
    Field...
    Field...
    Field...
    CreatedByUser int not null, -- Populate this on creation and never change it again
    ModifiedByUser int not null - populate this on every row update including insert

Your Q1 isn't really about Role vs User management (ie: authorizations) at this point. It's about audit tracking within your application.

And the way you do that is you capture the ID of the user who created the record in question with the record, so that later you can filter on that ID.

Pseudo database structure

Table Sales
    Field...
    Field...
    Field...
    CreatedByUser int not null, -- Populate this on creation and never change it again
    ModifiedByUser int not null - populate this on every row update including insert
趁年轻赶紧闹 2024-11-23 02:29:33

请参阅 ASP.NET 配置文件属性

假设数据库中的记录对应于用户的唯一 ID,您可以将唯一 ID 存储在每个用户的配置文件属性中。

See ASP.NET Profile Properties.

Assuming the records in the database correspond to a unique ID for a user, you can store the unique id in a profile property per user.

北城孤痞 2024-11-23 02:29:33

1)如果您想按创建用户过滤记录,则需要在表中记录创建该记录的用户的ID。您可以通过 User.Identity.Name 访问当前用户的名称,并通过 User.ProviderUserKey 访问其 ID(取决于提供商)。

2) 会话是在 ASP.NET 中自动创建的,并且只要您有正确配置的 MembershipProvider,您就可以使用 User 对象检索所有需要的用户信息,如上所示。

听起来您对 ASP.NET 成员资格和角色功能有点不熟悉,因为它们实际上设置得很好,可以完成您所描述的任务。我建议您查看本教程系列:

https://web.archive.org/web/20211020202857/http://www.4guysfromrolla.com/articles/120705-1.aspx

1) If you want to filter records by the creating user, you need to record in your table the ID of the user who created the record. You can access the name of current user through User.Identity.Name and their ID (provider-dependent) through User.ProviderUserKey.

2) Sessions are created automatically in ASP.NET and provided you have a properly configured MembershipProvider, you can retrieve all the needed user info using the User object as shown above.

It sounds like you are a little unfamiliar with ASP.NET Membership and Roles capabilities, because they are actually set up quite well to accomplish what you are describing. I would recommend checking out this tutorial series:

https://web.archive.org/web/20211020202857/http://www.4guysfromrolla.com/articles/120705-1.aspx

月亮邮递员 2024-11-23 02:29:33

您正在谈论身份验证和授权。对于问题 1,您需要实现一个自定义授权提供程序以允许用户级别控制 http:// /msdn.microsoft.com/en-us/library/aa479048.aspx 对于问题 2,一旦您登录并通过身份验证,会话将包含一个 userprinciple 对象,该对象自动包含信息。

You are talking about Authentication and Authorization. For question 1 you and implement a custom authorization provider to allow for user level control http://msdn.microsoft.com/en-us/library/aa479048.aspx For question 2, once you log in and are Authenticated, the session contains a userprinciple object that has the info in it automatically.

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