MVC 4 Form Authentication using Azure SQL

  1. Create a project for MVC 4 Internet Application.
  2. By default, It is configured to use localDB for forms authentication.  We want to use Azure SQL instead.
  3. Add the following to web.config <system.web>
  4. <profile defaultProvider="DefaultProfileProvider">
    <providers>
    <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
    </providers>
    </profile>
    <membership defaultProvider="DefaultMembershipProvider">
    <providers>
    <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
    </providers>
    </membership>
    <roleManager enabled="true" defaultProvider="DefaultRoleProvider">
    <providers>
    <add connectionStringName="DefaultConnection" applicationName="/" name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </providers>
    </roleManager>

  5. change the connection string “DefaultConnection” to use Azure SQL.
  6. <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=tcp:server123.database.windows.net,1433;Initial Catalog=DB123;User ID=user123@server123;Password=pass123;Trusted_Connection=False;Encrypt=True;" providerName="System.Data.SqlClient" />
    </connectionStrings>

  7. Install NuGet package “Microsoft ASP.NET Universal Providers Core Libraries” to your MVC 4 project.
  8. If you are using VS 2012, you can go to top menu Project –> ASP.NET Configuration.  Now you can manage roles/users.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s