1

Currently a User could be an administrator, a janitor, a teacher etc.. We currently are using the default providers.

Soon there should be multiple clubs. All the roles will be the same and available in all the clubs. Users could be in multiple clubs and have different roles in different clubs or they also could be in none.

The roles and clubs should be saved in a database.

Is there an easy way to do this. Ideally I would like to do something like this.

[Authorize Roles = RoleName.Foo + Clubname.Bar]
Philippe
  • 1,715
  • 4
  • 25
  • 49

3 Answers3

2

You can use Role Provider class to customize its behaviour and have it implemented your way like it shows here ASP.NET MVC - Alternative to Role Provider?

At least to get you started and have some fresh ideas.

Hope this helps.

Community
  • 1
  • 1
Display Name
  • 4,672
  • 1
  • 33
  • 43
  • +1: This seems to me to be the most extensible method of doing this without complicating the system. – Joel Etherton Sep 28 '12 at 14:50
  • But he doesn't use a Role Provider in the linked example. Am I getting something wrong? – Philippe Oct 02 '12 at 08:54
  • Thanks for the right answer. What I meant (reread the answer) is you *either* use `Role Provider` or its alternative. As Joel mentioned is his comment - the most extensible (meaning simple, easy, readable, mainteinable) solution. Thanks again. – Display Name Mar 19 '13 at 17:04
1

With the default Authorize attribute roles are just string names. Some people have subclassed it to accept enum Roles.

Perhaps that you could create all clubs as roles and all roles as roles and require you to have both the Club Name Role and the appropriate role level. However that seems like a corruption of the meaning of Roles. I doubt that you can do this without a custom authorize process.

I would look at creating a custom authorize attribute that inherits from Authorize attribute and you can extend it to take additional information. You could look at extending/customising your membership system using Simple Membership provider

Community
  • 1
  • 1
GraemeMiller
  • 11,973
  • 8
  • 57
  • 111
0

You could create role names such as "Administrator.Club1" and "Janitor.Club2".

This assumes a relatively small number of clubs.

Joe
  • 122,218
  • 32
  • 205
  • 338
  • Would this also mean that I'd have to save all this in the same Table? I would prefer not to do that. – Philippe Sep 28 '12 at 09:19