Upgrading a Web Application Using SimpleMembership to ASP.NET MVC 5

I recently tried to upgrade the SimpleSecurity reference application from MVC 4 to MVC 5 and ran into some issues.  SimpleSecurity encapsulates and decouples SimpleMembership from your ASP.NET application and the underlying issue was compatibility with the WebMatrix assemblies that SimpleMembership uses and the new assemblies for MVC version 5, Web API version 5, and Razor version 3.

I followed the instruction for upgrading to MVC 5 that are posted here and received this error on application start.
Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()' to access security critical method 'System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)' failed.

I did some research and found that others were having the same issue. Well it turns out I did not follow the instructions exactly.  Here is one note in the instructions I did not pay close attention to.

Note: Microsoft-Web-Helpers has been replaced  with Microsoft.AspNet.WebHelpers. You should remove the old package first,  and then install the newer package. 

I opened up the NuGet Package Manager and installed the package Microsoft.AspNet.WebHelpers and things started to work.  Note that when you create a new MVC 5 application and try to incorporate SimpleSecurity or SimpleMembership you will hit the same issue because Microsoft.AspNet.WebHelpers  is not installed by default.  It has to be present for SimpleMembership to run correctly.

I verified that all of the features in the reference application are working correctly after the upgrade.  Even the generation of the emails using Postal worked, which I was not sure of because of the upgrade of Razor as well.

One change I needed to make to the SimpleSecurity assembly was to remove the filters AuthorizeAttribute and BasicAuthorizeAttribute and put them in a separate assembly.  I did this because they are dependent upon MVC and Web API assemblies.  So now there is a version for MVC 4 and another for MVC 5.

You can get the source code for the MVC 5 version of the Reference Application from the SimpleSecurity Project Source Code page. You will find it under SimpleSecurityMVC5\SeedSimpleUpgradeTo5.

Popular posts from this blog

Using Claims in ASP.NET Identity

Adding Email Confirmation to ASP.NET Identity in MVC 5

Customizing ASP.NET Identity in MVC 5