Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Group Membership to Custom Membership/Roles provider

Being fairly new to the MVC Framework, I am trying to establish a custom Membership provider which can support the concept of Groups or departments.

I need to assign each user to belong to one (and only one) of several groups - each group (and its members) can only view records which belong to it - identified by the GroupId.

I need to somehow store this groupid within the users profile so that when they are logged in and call (for example) the Index method on the controller, the groupid is passed which will then filter the records which the user can see.

I am sure it is a straightforward approach, but I seem to have a mental block with it.

Any insight will be helpful ( and probably embarassingly simple!)

Roger

like image 427
RogerDodge Avatar asked Nov 05 '22 19:11

RogerDodge


1 Answers

I wonder if you could use "roles" instead of "groups". Permissions can be handled easily with roles. Usually, a role is something like admin, manager, superuser, user, guest. But couldn't you use roles for your purposes?

Here's an explanation of using roles in the Membership provider: How To: Use Role Manager in ASP.NET 2.0. You can find lots more by searching for "roles" instead of "groups".

And in case you don't have the Membership source code as a reference, you can download it from this page Microsoft ASP.NET 2.0 Providers: Introduction to see how they code for roles in the basic version.

like image 116
DOK Avatar answered Nov 15 '22 13:11

DOK