If you want to emulate the Login experience into the initial development workflow, you can get stuck on Azure websites with the SimpeMembership framework included in the MVC 4 project template.
Typically the login screen is the first part of a user workflow. Often it is the entryway to a menuing system in a web application. As you start your MVC 4 project, you want to start out with the rich starting point using the Internet Web Application templates. They provide a framework for SimpleMembership identity management and External Identity Providers such as Microsoft Live, Facebook, and others. So, while you want the features later, the WebSecurity framework can get in your way initially.
Using the code
Disable SimpleMembership from MVC 4 Internet Web Project Template
Step 1. – Comment out the “
DefaultConnection” in the web.config file.
Step 2 – Modify InitializeSimpleMembershipAttribute.cs to remove any attempt to initialize
SimpleMembership. It resides in the “Filters” folder of the project. I left the namespace and commented out the entire class with the class attributes.
AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public sealed class InitializeSimpleMembershipAttribute : ActionFilterAttribute
private static SimpleMembershipInitializer _initializer;
private static object _initializerLock = new object();
private static bool _isInitialized;
public override void OnActionExecuting(ActionExecutingContext filterContext)
Step 3 – Modify AccountController.cs under the Controllers folder to remove any attempt to initialize
Step3a – Comment out the
[InitializeSimpleMembership] attribute just above the
AccountController class definition.
public class AccountController : Controller
. . .
Step3c – Comment out the call to
WebSecurity.Login in the
Login function. This is in a if statement. After it is commented out, you will receive an “Unreachable code detected” warning since it will always take the same path. Not to worry as it is only temporary.
public ActionResult Login(LoginModel model, string returnUrl)
if (ModelState.IsValid && WebSecurity.Login(model.UserName,
model.Password, persistCookie: model.RememberMe))
return RedirectToAction("DisplayMenu", "MainMenu");
. . .
Step3d – Disable the calls to
WebSecurity in the
[HttpPost] Register function. I Ended up just returning ASAP so that the code is never reached. This will also cause an “Unreachable code detected” warning.
public ActionResult Register(RegisterModel model)
. . .
Points of Interest
I wasn’t ready to setup a database quite yet and I couldn’t get localdb to work quickly for SimpleMembership on the Azure Web Site. It is ok, since it won’t work at scale out anyway, but if you’re struggling just trying to get development started using Azure Web Sites and MVC 4, it could impede your progress. See Section 001 – Disable Simple Membership.
- r001v001a – 05/09/2013 – Initial revision.