Question

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]
Was it helpful?

Solution

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.

OTHER TIPS

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

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

This assumes a relatively small number of clubs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top