I'm wondering how to use the Role Manager feature with the SimpleMembership
system included in ASP.NET MVC 4, specifically how to build a controller that manages all data associated with Roles, and using the webpage_Roles
table that SimpleMembership
creates when a project is created with a Internet Template. Is there a way to automate this within the Login/Register actions in the AccountController?
Well, I am no expert on ASP.NET MVC4 but as a task I have set for myself, I wanted to create Role Based site access.
ASP.NET MVC4 is an excellent resource! I do have complaints about the lack of information and difficulty to implement Roles in MVC4.
To achieve the task one can implement SimpleMembership and SimpleRoles. See the below links:
The above two links explain a lot and have some very basic code examples but unfortunately the solution download is not available in the first URL.
In addition to the above:
This last article goes into a much better detail and also gives source code to peruse.
In web.config add the following
<profile defaultProvider="SimpleProfileProvider">
<providers>
<add name="SimpleProfileProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" connectionStringName="DNMXEntities" applicationName="/" />
</providers>
</profile>
<membership defaultProvider="SimpleMembershipProvider">
<providers>
<add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
</providers>
</membership>
<roleManager defaultProvider="SimpleRoleProvider">
<providers>
<add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
</providers>
</roleManager>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With