MVC: Membership Starter Kit

// April 2nd, 2008 // MVC

A newer version of the Membership Starter Kit is now available. Click here to see what has changed.

Introduction

One of my very first blog posts (and most definitely my most popular so far) revolved around how to integrate ASP.Net membership and forms authentication into the ASP.Net MVC framework which had just been released in it’s December CTP flavor. It has remained popular to this day, but unfortunately the Preview 2 release of the MVC framework has caused much of the code I released in that article to no longer function correctly.

Even before the release of Preview 2, I had been planning to extend the samples I was providing to offer more useful features. I don’t know about you, but nearly every website I ever create with ASP.Net requires some kind of security/membership system. My preference is to use the built-in system when possible (except for the horrible Profiles sub-system). This means creating login, logout, & registration functionality every time, as well as creating administrative screens for managing the users that enter your system.

WebForms provides some controls to help with the login and registration process, but user administration has always been delegated to either (a) the built-in tool that runs separately and doesn’t work remotely or (b) rolling your own solution. The development of the MVC framework seems to me like a good time to resolve this scenario and provide the community with an array of pre-built tools to help boot-strap projects so that we can stop working on infrastructure and start working on the heart of the individual application.

With that in mind I have created a CodePlex project: the ASP.Net MVC Membership Starter Kit. It currently provides controllers and views for all of the common authentication and user administration needs, including:

  • Login/Logout
  • Registration
  • List of Registered Users
  • User Details / Administration
  • Role Management

A big thanks goes out to Rob Conery, as I borrowed his recent Authentication Filters and included those, along with my recently released Error Handling Filters.

Okay, enough wall o’text. Let’s take a look at some screenshots:

Screenshot Tour

Here is the menu when you first log in:

Menu-LoggedOut

The registration page:

Registration

The login page (note that the Administrator’s credentials are displayed to make it easy to get started, you’ll obviously want to change them and remove that note):

Login

Having logged in, here is what the menu looks like now:

Menu-LoggedIn

The current options upon clicking the Security tab:

Security

Clicking “Manage Users” brings you to a list of all users currently registered:

ManageUsers

Clicking on the user takes you to a form that allows you to view their details and edit a few aspects of their profile…

User-Top

as well as view/change the roles they are in and help with password issues:

User-Bottom

From the Security tab you can also go to a list of all the system’s roles, from which you can add/delete roles as you need:

Roles

Clicking on a role from the roles list or the user profile allows you to view/modify the users in that role:

UsersInRole

And finally, the Security tab offers a link to another registration form, geared toward Administrators:

CreateUser

NSFAQ (Not-So Frequently Asked Questions)

Q: Does this compete with MvcContrib?
A: No. MvcContrib is a great project that aims to features like alternate routing and view engines, and IoC integration. This project is simply a starter kit to help get membership-based applications off the ground a little quicker. There is no reason you could not use both projects together.

Q: What dependencies does using this starter kit saddle me with?
A: Ideally, none, other than the ASP.Net Membership API. Every measure will be taken to avoid using third party libraries, be it JavaScript or .Net. We will strive to separate the code and rely on default settings as much as possible to make it easy for you to customize your installation without anything in the starter kit getting in the way.

Q: Who is responsible for this?
A: Currently, only me, but I’d like that to change! I’m keenly interested in finding a few other developers that would like to contribute to enhancing the starter kit. Please contact me if you’d like to help!

What’s Next?

There are a few features missing that I would like to include in the very short term. Primarily these are features for end-users, like Change Password and Forgot My Password (both of which are currently available on the administration side). Beyond that, visual cleanup of the forms (and separation of the style sheets) as well as a bit of AJAX-ification of the forms would be nice. If you use the starter kit and have suggestions or criticisms, please post to the Discussions forum or Issue Tracker!

You can download the latest release from the CodePlex project. I hope you all find it useful!

Kick It on DotNetKicks.comShout It on DotNetShoutOuts.com

12 Responses to “MVC: Membership Starter Kit”

  1. tgmdbm says:

    Nice work Troy.

  2. Robert says:

    Nice – i created a similar solution (for download scroll down – the sourcecode is in english ;) ) :
    http://code-inside.de/blog/2008/03/13/aspnet-mvc-preview-2-membership/

    User can set a new password (or can get a new password if it was lost) and store some user profile data (without using the asp.net profile system – i implement a very simple profile table).

  3. Troy Goode says:

    Very nice Robert, I was unaware that you had already posted something similar. Great minds think alike right? ;-)

  4. Robert says:

    Right ;)

    I working now on a little project an use nearly the same “SecurityController” as you – passing the data to the controller via parameters and not using “this.Request.Form['...']“.

    I should upload more stuff on codeplex ;)

  5. Troy Goode says:

    In my original post (for preview1: http://www.squaredroot.com/post/2007/12/ASPNet-MVC-Membership-Basics.aspx) I passed all of the data through parameters. One thing I found that I did not like when doing that though is that you can not strongly-type your form tag declaration (which I still have not gone back and fixed yet, but plan to…).

    For instance:
    < % using( Html.Form( x=>x.Update() ){ %>…< % } %>

    Would be difficult to do if .Update() expected a million parameters that you did not know the value for yet.

    If you know a way around this, please let me know!

  6. I posted an update to this over at my blog: http://blog.maartenballiauw.be/post/2008/04/ASPNet-MVC-Membership-Starter-Kit.aspx

    No release material yet, but I’m too excited about this to keep it silent!

  7. Gabriel says:

    Thanks for this! I can’t remember the last time a MS technology generated this much buzz. I’m loving it.

  8. Troy Goode says:

    No problem Gabriel. Keep your eyes peeled, because this weekend we should be releasing a new version of the starter kit including many enhancements. =)

  9. mateo says:

    Great lib you’ve created. I started working with it today and its up and running. One thing though, when the username contains a dot like Carey.Price, i receive an error. Should it be encoded?

    thanks and keep up the good work

  10. Troy Goode says:

    Mateo,

    That, unfortunately, is due to the way routing worked in Preview 2 of the MVC framework. The ‘.’ character acts as a delimiter in urls, causing “Carey.Price” to be split up into two arguments to the method “Carey” and “Price.”

    The good news is that this paticular issue with routing was addressed in yesterday’s new release of the MVC framework (the interim source release on Codeplex). I have already upgraded the starter kit code to work with the interim release and we will be publishing a new version of the starter kit soon (hopefully this weekend).

  11. Hi there,

    just started getting into MVC and needed something just like this, thanks for writing it!

    Its been easy to use and configure which means I can focus on my real code, thanks again

  12. Harish says:

    Hello,

    Nice Work …

    Do you have any idea of the creating users profile with some additional fields (aspnet_profile)??