Click here to Skip to main content
13,247,448 members (77,224 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


Posted 10 May 2013

Disable MVC 4 SimpleMembership for early development on Azure websites

, 10 May 2013
Rate this:
Please Sign up or sign in to vote.
Early dev using MVC 4 on Azure websites can get stuck on SimpleMembership.


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.


<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial 
     providerName="System.Data.SqlClient" />

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.

namespace RadvSampleDaycareApp001.Filters
    //RAD-001 - Disable Simple Membership
    [AttributeUsage(AttributeTargets.Class | 
      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)
            // Ensure ASP.NET Simple Membership is initialized only once per app start
            //... NOTE: not all code shown for brevity.
            //   Just comment out the whole class. We will enable it later.

Step 3 – Modify AccountController.cs under the Controllers folder to remove any attempt to initialize SimpleMembership.

Step3a – Comment out the [InitializeSimpleMembership] attribute just above the AccountController class definition.

namespace RadvSampleDaycareApp001.Controllers
    //RAD-001 - disable SimpleMemebership [InitializeSimpleMembership]
    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)
    //RAD-001-TEMP - disable SimpleMemebership
    if (ModelState.IsValid && WebSecurity.Login(model.UserName, 
        model.Password, persistCookie: model.RememberMe))
    //RAD-001-TEMP - Added if statement below to keep the block 
        //RAD-002-CHG - Changed the default return to now go
        // the the main menu controller on successful login
        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)
    //RAD-001-TEMP - The code below returns immediately to disable the calls to WebSecurity
    return View(model);
    if (ModelState.IsValid)
        . . .

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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Chief Technology Officer RadventureSoft LLC
United States United States
Enterprise ISV leader and chief architect of enterprise software systems. Original architect and developer of the TriZetto Facets software system for the Healthcare Payor marketplace. 20+ years experience in all aspects of software development and hosting services. My passion is in developing rock-solid software patterns and applying them to the ever changing technologies to provide solutions that last. Foundations, Frameworks, Code-Generation, Architecture Placement and selecting the right technology are all criticle to developing systems that stand the test of time.

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 10 May 2013
Article Copyright 2013 by radv
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid