PLTippen – Part 3 – granting access and role based menues


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:

Roles.IsUserInRole("Administrator")

See source code for full _layout.cshtml.

Advertisements

One thought on “PLTippen – Part 3 – granting access and role based menues

  1. Pingback: Summer-time « Sveroa's Developer Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s