I have been playing around the generated MCV4 web application for the last few evenings. I’m not particular familiar with the Model-View-Controller pattern yet, but I’ve been able to create new views and adding role-based sensitive menues for these new views to my application 🙂
In addition to the MVC pattern, I’m pretty new to the Razor Engine. I found an introduction blog with loads of examples by Scott Guthrie. But for the time being, I will just playing around with my code and learn by doing and failing.
I have decided to allow people to register for my site and create an “Approve” page where I grant access by adding a role to registered user. I have added firstname and lastname to the register page and will add these as properties in the membership tables to be able to disinguish who the registered person is. I will create a schedules stored procedure that validated the registered users and delete users that has an invalid email address.
Enabling Role manager to your membership provider:
<roleManager defaultProvider="AspNetSqlRoleProvider" enabled="true"> <providers> <clear /> <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="DefaultConnection" applicationName="/" /> </providers> </roleManager>
This enables me to call the Roles-methods like this in my _layouts.cshtml file to create a role-based menu item:
See source code for full _layout.cshtml.