开发者

How do I implement a custom role provider which supports sub roles?

开发者 https://www.devze.com 2023-01-09 09:14 出处:网络
Are there any good guides on how to implement a custom role provider which has support for parent and child roles?

Are there any good guides on how to implement a custom role provider which has support for parent and child roles?

I have a requirement to have high level Role permissions as per the usual Role provider functionality. However, I also have a requ开发者_如何学编程irement to further breakdown permissions into sub roles. I toyed with the idea of having further role instances for sub permissions but I'd prefer to have a native solution which allows for sub roles.

For instance:

[IT]

[IT] > [Admin]

[Extranet]

[Extranet] > [Admin]

In this scenario, the "Admin" role is actually 2 distinct roles, one for IT and one for Extranet scenarios. Ideally, there is no association between the 2 "Admin" roles because they are unique sub roles.

[Edit]: Following Igor's comment I feel I should clarify. The aspnetdb is already hosting multiple applications and therefore the use of the Application Name is not possible to segregate the sub roles as it is already being used to seperate the roles by application.


1) Use aggregation of permissions, why do you have to use inheritance? Just assign user to IT and Admin roles and their permissions will be concatenated.

2) Separate Admin(1) and Admin(2) by using Application Name. If I understood you it will be 2 different applications (otherwise rename one Admin to other name)

Luck.


Not sure if you're still looking for a viable solution, but I recently developed an application with similar requirements. I used the role provider to assign the basic roles. In your case, IT or Extranet. Then assign each user a status (it admin and extranet admin). Crest a session on login to store their status and use if statements to give access to subrole pages and views.


(Should probably tag this with asp.net)

I am unaware of any native (MS) solutions that support Role within Role solutions. If you do not need to provide a role within a role, and you can alway create roles like "IT", "IT_Admin", "Extranet", and "Extranet_Admin".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号