ASP.NET MVC Membership Management (Users and Roles)

Here at kmsystems we have really been diving into ASP.NET MVC with everyone in the team doing loads of learning, setting up some new projects using MVC and converting over some old ones. Not to be left out of all the MVC fun :) I've decided to dive in and port over a simple team management app we built called "Whos Doin Wot" from the Morfik 2.0 RIA Tool which I put together a while ago now.

The new release of Whos Doin Wot isn't quite ready for use yet however I want to share some of the work I have done setting up user and role management. I'm a big fan of buy borrow, beg, steal before you build or role your own (just can't see the benefit of re-inventing the wheel if a great wheel already exists) so I started my search and found the following:

ASP.Net MVC Membership Starter Kit which is a really promising membership management tool and would have been exactly what I was looking for, unfortunately the current release does not work on MVC Release 1.0

ASP.NET MVC Membership Management Roni Schuetz which also looks great but costs 30 euros (around $50 Australian dollars) and given that it was just a blog post with no comments I wasn't too sure if I was just kissing my $50 goodbye (maybe I'll give it a go later).

As the options to buy, beg, borrow or steal were not that appealing and with the goal of learning more about MVC I decided to (god forbid) roll my own membership management. Anyway it wasn't going into a full blown management tool I wanted to keep it simple and light to just cover off the very basics.

If you are interested I have uploaded the source code for you to download modify and use in your own projects. This code is jsut a very basic base to start from and extend to meet your requirements. It would be great if you could share any improvements back here with us.

The code covers:

- List all users

- Add a new user

- Edit a user

- Delete a user

- View the roles associated to a user

- Remove a role from a user

- Add a role to a user

- List all roles

- Create a role

- Lists users in a role

- Delete a role

The code I created is based on using ASP.NET Membership in a SQL server database by default MVC points to a SQL Express database named "ASPNETDB.MDF"; under the application's "App_Data" directory. If you would like to use a different SQL server or dataabase update the "ApplicationServices"; connection string within the web.config file. You can run the "aspnet_regsql.exe" utility within the \Windows\Microsoft.NET\Framework\v2.0.50727\ directory to add membership and the other ASP.NET application services to any database.