Logo

Maarten Balliauw {blog}

ASP.NET, ASP.NET MVC, Azure, PHP, OpenXML, VSTS, ...

About the author

Maarten Balliauw is an MVP ASP.NET and is currently employed as .NET Software Engineer at RealDolmen. His interests are mainly web applications developed in ASP.NET (C#) or PHP.
More about me More about me
Send mail E-mail me


Microsoft Most Valuable Professional - MVP - ASP.NET

Subscribe to my RSS feed Follow me on Twitter! View Maarten Balliauw's profile on LinkedIn RealDolmen - Rock-solid passion for ICT
I'm a speaker at TechDays Belgium and TechDays Finland

Search

Latest Twitter

    Follow me on Twitter...

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

    © Copyright Maarten Balliauw 2010

    ASP.Net MVC Membership Starter Kit

    ASP.Net MVC Membership starter kit Yesterday, I read a cool blog post from Troy Goode about his new CodePlex project MvcMembership. I also noticed his call for help, so I decided to dedicate some of my evening hours to his project.

    Almost every (ASP.NET) website is using some form of authentication, in most cases based on ASP.NET membership. With this in mind, Troy started an ASP.NET MVC version of this. The current release version provides a sample application containing some membership functionality:

    • FormsAuthenticationController featuring:
      • Register action & view
      • Login action & view
      • Logout action
    • FormsAuthenticationAdministrationController featuring:
      • User List action & view
      • User Detail action & view
      • Role List action & view
      • Create User action & view
      • Change/Reset Password actions
      • Role Management actions
    • Custom Action Filters, including:
      • a RequiresAnonymousAttribute
      • a RequireAnyRoleAttribute
      • a RequireEveryRoleAttribute
      • a RedirectToActionOnErrorAttribute
      • a RedirectToUrlOnErrorAttribute

    After an evening of contributing code, there's additional functionality in the source control system:

    • FormsAuthenticationController featuring:
      • Reset password action & view
      • Retrieve password action & view
      • Change password action & view

    Also, I've been doing some massive refactoring to this project. Everything that is "generic" for most applications is now stripped out in a separate assembly still allowing situation-specific overrides. For example, if you use this MvcMembership framework, you can simply inherit the BaseFormsAuthenticationController class in your own code:

    namespace MvcMembership.Controllers
    {
        public class FormsAuthenticationController : StarterKit.Mvc.Membership.Controllers.BaseFormsAuthenticationController
        {
        // Nothing here... All is handled in the BaseFormsAuthenticationController class!
        }
    }

    Need a custom Login action? No problem!

    namespace MvcMembership.Controllers
    {
        public class FormsAuthenticationController : StarterKit.Mvc.Membership.Controllers.BaseFormsAuthenticationController
        {
            public override void Login()
            {
                // this is an override, additional ViewData can be set here
                base.Login();
            }
        }
    }

    Want to respond to some actions inside BaseFormsAuthenticationController? No problem either!

    namespace MvcMembership.Controllers
    {
        public class FormsAuthenticationController : StarterKit.Mvc.Membership.Controllers.BaseFormsAuthenticationController
        {
            public override void OnAfterResetPassword(string email, string userName, string newPassword)
            {
                // TODO: replace with sender e-mail address.
                MailMessage mailMessage = new MailMessage("sender@example.com", email);

                // TODO: replace with custom subject.
                mailMessage.Subject = "Your password";

                // TODO: replace with custom body.
                mailMessage.Body = string.Format("{0}, your password is: {1}.", userName, newPassword);

                // TODO: replace with the name of your SMTP server.
                SmtpClient smtpClient = new SmtpClient("localhost", 25);
                smtpClient.Send(mailMessage);
            }
        }
    }

    Let's hope the ASP.NET MVC team picks this up, as I think it's something lots of users would like to see. For now, it's a separate download from CodePlex.

    kick it on DotNetKicks.com  


    Comments

    gabriel United States |

    Friday, April 11, 2008 1:59 AM

    gabriel

    very cool!

    Andy |

    Wednesday, April 01, 2009 8:39 AM

    Andy

    Hey this is cool project,

    Does it work with MVC 1.0 ? The project on codeplex has been updated since feb ?

    Andy

    maartenba Belgium |

    Wednesday, April 01, 2009 8:43 AM

    maartenba

    Should work with MVC 1.0.

    Comments are closed