Skip to content
Go back

ASP.Net MVC Membership Starter Kit

Edit page

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:

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

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:

[code:c#]

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

[/code]

Need a custom Login action? No problem!

[code:c#]

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();
        }
    }
}

[/code]

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

[code:c#]

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("[email protected]", 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);
        }
    }
}

[/code]

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  


Edit page
Share this post on:

Previous Post
To all BlogEngine.NET users... Go patch!
Next Post
Reuse Excel business logic with PHPExcel