Posted 2nd of October 2012 by Kern Herskind Nightingale

Disclaimer: This is not tested thoroughly and I have only posted here for the benefit of people experimenting with MVC and Sitecore 6.6 technology preview.

I know there is no official MVC 4 support in the technology preview but I was looking at the upgrade path for a pure MVC application from MVC 3 to MVC 4 and it seemed almost to easy - here is what the ASP.NET team says you need to do: Upgrading an ASP.NET MVC 3 project to MVC 4

I thought I would give it a go with my Sitecore 6.6 test rig and after a bit of configuration work it appeared to be working. Here is what I changed to get Sitecore to work with a MVC 4 project:

I used the /Views/Web.config from a vanilla MVC 4 project.

In the /Web.config (the one that is distributed with Sitecore as Web.config.MVC) I added these keys to the appSettings:

<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />

And changed these assembly version numbers in the system.web/compilation section:

<!--<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral,PublicKeyToken=31BF3856AD364E35" />-->
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
<!--<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral,PublicKeyToken=31BF3856AD364E35" />-->
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral,PublicKeyToken=31BF3856AD364E35" />

And finally I had to add assembly bindings to make Sitecore use the correct MVC assemblies:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="4.0.0.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" /> 
      <bindingRedirect oldVersion="3.5.0.0" newVersion="4.5.0.0"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>

If you try this, let me know how you get on…



blog comments powered by Disqus

About the author

Kern is a Sitecore Specialist with more than 10 years experince achitecting and developing Sitecore solutions. Kern was awarded Sitecore MVP in 2009, 2011 and again in 2015.
Currently Kern is helping the Sitecore Product team in shaping the future of the platform.

Kern Herskind Nightingale