Adam Anderly

Husband, Father, Developer

  • About
  • Blog
  • Archives
  • Plugins
    • WooCommerce MailChimp
    • Wistia Responsive
  • Contact

Copyright © 2025
Adam Anderly · Log in

Using SimpleMembership in MVC3

August 11, 2011 By Adam 15 Comments

 

I have received a couple of questions over the past few weeks regarding how to properly get SimpleMembership to work with an MVC3 application. While it is pretty straightforward, the purpose of this post is to serve as a step-by-step “How To” setup SimpleMembership with an MVC 3 application from start to finish.

The following 4 simple steps will get you up and running with SimpleMembership in your MVC3 application in a matter of minutes. We’ll go into each step in more detail below.

  1. Create new Mvc3 Internet Application or use an existing one.
  2. Create your SqlServer, SqlExpress or SqlCompact4 database (we’ll be using SqlCompact4 in this example)
  3. Update Web.config with connection string to point to your database from step 2
  4. Install & Configure SimpleMembership.Sample package

Creating your MVC 3 Application

  1. Select File > New Project and Select ASP.NET MVC 3 Web Application.
  2. Pick your desired folder location and click Ok.
  3. Next, make sure Internet Application is selected and Razor is the View engine.
  4. In this case, we chosen to create a unit test project automatically for testing purposes.
  5. Choose OK to create your project.

Creating your database (SqlCompact4)

  1. Before we do anything else, we are going to create a SqlCompact4 database rather than using SQLExpress which is the default for new projects.
  2. To do so, right-click the App_Data directory and select Add > New Item.
  3. In the next dialog, select SQL Server Compact 4.0 Local Database, use “Database.sdf” as the filename and click Add.

Updating Web.config connection string

Now that our database is created, we need to update our connection string in Web.config to point to our SqlCompact4 database we just created.

  1. Open Web.config and locate the connection string named “Application Services”.
  2. Next, change the “Application Services” connectionString and providerName to the following:

<add name=“ApplicationServices“ connectionString=“data source=|DataDirectory|\Database.sdf“ providerName=“System.Data.SqlServerCe.4.0“ />

Installing & Configuring SimpleMembership

Now, that we have our application ready, SqlCompact database created and ready to go, now we can install SimpleMembership. For the sake of simplicity, I’m going to install the SimpleMembership.Mvc3.Sample package which include the sample account controller pre-wired for use with SimpleMembership.

  1. In Visual Studio, navigate to Tools > Library Package Manager > Manage NuGet Packages.
  2. Select Online from the left-hand pane and type in SimpleMembership in the search box at the top right.
  3. Select the SimpleMembership.Mvc3.Sample package and click Install.
  4. Next, delete the existing Controllers/AccountController.cs file that Visual Studio created for you.
  5. Rename Controllers/SimpleMembershipAccountController.cs to AccountController.cs
  6. Open App_Start/SimpleMembershipMvc3.cs and update it to point to the “ApplicationServices” connection string or your appropriate connection string.

That’s It!

You’re application is now ready to use SimpleMembership and you have a fully-functional AccountController.cs pre-wired to use the SimpleMembership API.

Enjoy!

Please post a comment if you have questions or run into issues.

The code is available here: SimpleMembership.Mvc3.Example.zip

Share this:

  • Twitter
  • LinkedIn
  • Email
  • Print
  • More
  • Reddit

Filed Under: Uncategorized

RSS

RSS Feed

Subscribe

Enter your email address to subscribe and receive new posts by email.

Find It Here

Top Posts

  • Cross-Cutting Concerns with MediatR Pipeline Behaviors
  • Blog
  • About Me
  • Archives
  • Contact

Recent Posts

  • Cross-Cutting Concerns with MediatR Pipeline Behaviors
  • Laravel User Timezone Aware Trait
  • Useful Laravel Model Traits: Gravatar
  • Laravel Transformable – An Eloquent Model Trait for Consumable Models
  • Gravity Forms + Microsoft Dynamics CRM

Categories

  • .NET (12)
  • ASP.NET Core (1)
  • ASP.NET MVC (7)
  • Dependency Injection (3)
  • Laravel (3)
  • Laravel Traits (2)
  • MediatR (1)
  • Node.js (2)
  • NuGet (5)
  • PHP (2)
  • REST (4)
  • Silverlight (5)
  • Uncategorized (3)
  • WordPress (7)
  • WordPress Plugins (7)

Tags

.NET APIs ASP.NET Core ASP.NET MVC Azure Caching cli CRM Dependency Injection dns dnsimple Dynamics Dynamics CRM Expansive Fallback Gravity Forms iPhone Laravel Laravel Traits MailChimp MediatR Microsoft Dynamics CRM MobileMe Node.js NuGet PHP Polly REST Retry Rounding Scrutor Silverlight SimpleMembership sublime-text-2 VS2010 Wistia WooCommerce WordPress WordPress Plugins
  • About
  • Blog
  • Archives
  • Plugins
    • WooCommerce MailChimp
    • Wistia Responsive
  • Contact
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.