I’ve received several requests to update my original post dealing with adding a confirmation step to the standard ASP.NET MVC registration process so that it can work with ASP.NET MVC3. This seemed like a perfect place to use (and learn) Nuget, so you don’t have to deal with all the steps of creating the methods, modifying the views, etc.
For now, I’m going to assume that you already have Nuget installed and you have some idea of how to use it. If you don’t, read through the instructions at the Nuget site, or check out blog posts by Scott Hanselman or Phil Haack. If you still need help, post something in the comments and I’ll expand this post to include a Getting Started section.
Step 1a – Create a New Project
In Visual Studio, create a new ASP.NET MVC 3 Internet Application.
Step 1b – Work with an Existing Project
This will work with an existing project, but I’m assuming that you’re using default everything. If you’ve modified the AccountController or AccountModels in an uber custom way, you’ll likely experience pain. If you’re using out-of-the-box functionality, you won’t have any issues. And by “won’t”, I mean you’re completely on your own.
Step 2 – A little preparation
Now that you got your project, rename Controllers/AccountController.cs and Views/Account/LogOn.cshtml by adding “.old” to each file.
This needs to be done because Nuget cannot modify existing files (or at least I don’t know how to do it). These files are included in the Nuget package, and the default behavior of Nuget is to ignore any files that it finds on disk that match files in the package. By renaming them, if you have any custom code in there, you won’t lose it – you’ll just need to port it over to the new files.
Step 3 – Installing the package
A. From the console:
If you’re a fan of the console, Select Tools | Library Package Manager | Package Manager Console. At the console prompt type: install-package MvcConfirmationEmail. Nuget will download the package and modify your project accordingly.
B. From the User Interface:
Right-click on your project root, and select “Manage Nuget Packages…”. When the dialog window pops-up, enter “ConfirmationEmail” (one word) in the search text box in the upper right corner.
After a few seconds, it will find the MvcConfirmationEmail package (shown above). Click the install button, and it will download and install the package into your project.
If you didn’t rename the files as noted in Step 2 – this won’t work, and you will need to uninstall the package (PM>uninstall-package MvcConfirmationEmail), rename the files, and do this again.
Step 4 – Update web.config
When Nuget installed the package, a few additions were made to web.config so that you can configure your email service provider’s settings.
A. Email From Name
When you send an email to someone during the registration process, it has to come from a named account. Open up web.config and find the configuration\appSettings section. There is a key named MvcConfirmationEmailFromAccount. Change the value to the account name that will be sending the email. I’ve been using Gmail as my test account and it works great.
B. Mail Settings
You need to configure the settings for your email service provider. Head down to the bottom of the config file, and you’ll find the system.net\mailSettings\smtp node. Set the appropriate values for host, userName, password, and port, Gmail requires port 587 for SMTP – if you’re not using Gmail – you will need to check with your service provider to see what this should be.
That’s it! You should now be able to run the application and have the same functionality/workflow available in the original post. If you run into any problems or have any questions, please post down in the comments section and I’ll be happy to walk through your issues.
UPDATE 10/18/2011: I created a sample site on AppHarbor that you can use to test the functionality/workflow. http://confirm.apphb.com.