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.

Knockout and JQuery Mobile

I found that Jquery mobile stuff does not work once it is inside of knockout.

In the following html, “Test Text” cannot be shown even when one clicks on the + to expand.

It is probably better to switch from jquery mobile to bootstrap since bootstrap is pure CSS.  In this case, I think knockout and jquery mobile are interfering with each other, probably in UI behaviors implemented in javascript.

 

<table>
<tbody data-bind="with: chosenHearingSummary">
<tr>
<td>
<div data-role="collapsible">
<h3>Internal</h3>
Test Text
</div>
</td>
</tr>
</tbody>
</table>
Solution:
 
HTML:
<table>
<tbody data-bind="with: someEntity">
<tr>
<td>
<div data-role="collapsible" data-bind="click: $parent.toggleInternal">
<h3>Internal Section</h3>
</div>
<div class="internalSection" data-bind="visible: $parent.expandedInternal">
<label data-bind="text: ID"></label>
<label data-bind="text: InternalID"></label>
</div>
</td>
</tr>
</tbody>
</table>
 

View Model:

var viewModel = function () {
var self = this;
self.expandedInternal = ko.observable(true);

self.toggleInternal = function () {
console.log('toggleInternal called');
self.expandedInternal(!self.expandedInternal());
};
}
 
Reference:
 
 

NinjectWebCommon Throws InvalidOperationException

Exception Details: System.InvalidOperationException: Sequence contains no elements

This error is caused by the fact that there are 2 projects with App_Start/NinjectWebCommon.cs

Removing the file eliminates the error.

Note: if you are nu-getting Ninject.Web.Common because you need to reference Ninject.Web.Common assembly for one of your class library project, you can safely remove the “App_Start” folder and “NinjectWebCommon.cs”.  It is meant for web/web api projects.