Question

what is the best way to manage roles in MVC 4? I found this tutorial:

http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-7

but I want to be flexible and add the back office user the power to create and assing roles to registred user.

Many thanks

Was it helpful?

Solution 2

I don't think that the framework provides an out of the box solution for managing users and roles. It should however be quite easy to roll your own, especially if you use the new SimpleMembership provider.

You can also take a look at the SecurityGuard project, which seems quite nice, but I haven't tried it yet.

OTHER TIPS

The ASP.NET Configuration site mentioned in that tutorial does not even work with SimpleMembershipProvider.

You will need a few custom pages to do the following:

  • List users
  • Create/Edit user where you display a list of roles.

Then you can just use the built-in functions such as:

Roles.RoleExists(role)
Roles.CreateRole(role);
Roles.IsUserInRole(username, role)
Roles.AddUserToRole(username, role);    

This assumes you are using a built-in provider and the data tables generated by ASP.NET. You can also inherit from the RoleProvider class and implement your own methods.

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