具有不同类型角色的 ASP.NET 提供程序

发布于 2024-08-11 21:44:55 字数 508 浏览 2 评论 0原文

在授权用户时,我需要考虑不同类型的角色。 例如:约翰必须拥有职位经理并且属于办公用品部门才能订购新计算机。

角色的问题是 Roles.GetRolesForUser("John") 只能返回字符串数组。

我应该使用自定义 roleProvider 和自定义 roleManager 吗? 或者我应该开发一个自定义 ProfileManager 来添加像 GetUsersWithProfileProperties() 这样的方法?

欢迎任何建议!

Thibaut

编辑:上面的例子被简化了,我可以有多达 4 种类型的角色,它们是 4 个不同的集合。

编辑:我发现一个非常相似的问题

I have different types of Roles to take into account when authorizing a user.
For example: John must have Position Manager and be part of the Office Supplies Department to order a new computer.

Problem with Roles is Roles.GetRolesForUser("John") can only return a string array.

Should I go with a custom roleProvider and custom roleManager?
or should I develop a custom ProfileManager to add methods like GetUsersWithProfileProperties()?

Any suggestion is welcome!

Thibaut

EDIT: the above example is simplified I could have a much as 4 types of roles which are 4 different collections.

EDIT: I found a very similar question

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

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

发布评论

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

评论(4

风柔一江水 2024-08-18 21:44:55

从你写的内容来看;我相信您需要的一切目前都是开箱即用的:

    // Return all Users in a  Role
    string[] users;
    users = Roles.GetUsersInRole("RoleName");
    // Return all Roles for a User
    string[] roles;
    roles = Roles.GetRolesForUser();
    // Search through Membership store locating users with a role
    MembershipUserCollection mu;
    mu = Membership.GetAllUsers();
    // Loop through all membership users looking for users in a role

    foreach(MembershipUser m in mu){
        if(Roles.IsUserInRole(m.UserName, "Role Name")){
            // Do something

            // We can even nest to x levels
            if (Roles.IsUserInRole(m.UserName, "Another Role")){

                // Do something else
            }
        }
    }

请澄清我是否误解了您的问题。

From what you write; I believe that everything you need is currently available out of the box:

    // Return all Users in a  Role
    string[] users;
    users = Roles.GetUsersInRole("RoleName");
    // Return all Roles for a User
    string[] roles;
    roles = Roles.GetRolesForUser();
    // Search through Membership store locating users with a role
    MembershipUserCollection mu;
    mu = Membership.GetAllUsers();
    // Loop through all membership users looking for users in a role

    foreach(MembershipUser m in mu){
        if(Roles.IsUserInRole(m.UserName, "Role Name")){
            // Do something

            // We can even nest to x levels
            if (Roles.IsUserInRole(m.UserName, "Another Role")){

                // Do something else
            }
        }
    }

Please clarify if I have misunderstood your question.

花辞树 2024-08-18 21:44:55

为什么不创建一个具有路径到级别 typew 约定的“CompositeRoleProvider”来访问每个从属角色提供程序。您仍然需要创建多个角色提供程序,但您的复合或顶级提供程序会为您完成所有工作。
我计划用 ProfileProvider 做类似的事情

why not create a "CompositeRoleProvider" with a Path-To-Level typew convention for accessing each subordinate role provider. You will still have to create multiple role providers, but your Composite or Top-Level Provider does all of the work for you.
I plan to do a similar thing with ProfileProvider

月依秋水 2024-08-18 21:44:55

我正在研究如何解决一个非常相似的问题,我得出的结论是,最好的办法是实现自定义角色提供程序。

我使用这个(http://msdn.microsoft.com/en-us/library/317sza4k(v=vs.100).aspx)作为基础,我将实现我的方法,例如(IsManager,GetDepartment,ecc) 。

数据将存储在连接到 aspnet_users 表的自定义表中。

希望它可以帮助将来的人:)

I'm studying how to solve a pretty similar problem and I've come to a conclusion that the best thing to do is to implement a custom role provider.

I'm using this (http://msdn.microsoft.com/en-us/library/317sza4k(v=vs.100).aspx) as a base and I will implement my methods like (IsManager, GetDepartment, ecc).

Data will be stored in custom tables that are joined to the aspnet_users table.

Hope it may help someone in the future :)

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