Jim Rogers

Lives in Baton Rouge, LA, with two dogs, one cat, and one lovely wife. I'm a lead developer for GCR Incorporated.

Katrin and Jim

Month List

MVC3 in Azure

by Jim Dec 03, 2010 1:19 PM

The Azure SDK and tools haven’t caught up with the MVC3 release candidate yet, but MVC3 is compatible with Azure. Here’s how to get a basic MVC3 web role up and running in the cloud.

I’ve got the Azure SDK and tools version 1.3 installed, and of course the MVC3 release candidate.

Open Visual Studio 2010 and create a new project and solution, choosing the Windows Azure Project. Choose the MVC2 web role:

fwrlcckf

Now add a new project to your solution; this is a temporary project for copying settings and whatnot.

k4u53sry

For the project template, I’ve chosen “internet application” with the razor view engine.

Now for the conversion – first we delete the System.Web.Mvc reference from our MVC2 web role and reference the MVC3 assembly instead.

The default MVC3 application also references System.Web.Helpers, which isn’t in the MVC2 app. Add that reference.

The web.config files have a number of differences; just copy the contents of the v3 file over the v2 file.

Delete the temporary MVC3 web project, leaving only the original web role.

At this point you can hit F5 and run locally. The account pages won’t work, because you’re pointed to a SQL Express database, but that’s outside the scope of this demo :-)

Now go to the fancy new Silverlight portal and add a hosted service account, with a corresponding storage account (which we just need for our logging right now.) Click the “view” button next to the primary access key and copy it to the clipboard.

image

The service definition and service configuration files have changed a bit in the 1.3 SDK, with regard to diagnostics, but the diagnostics connection string value works as before. Update the AccountName and AccountKey values.

<ConfigurationSettings>
<!--
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"
value="UseDevelopmentStorage=true" />
-->
<
Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=mvc3demo;AccountKey=[your key]" />
</
ConfigurationSettings>

We’re almost ready. The MVC3 release won’t be installed in our Azure instance, so we’ll need to ensure that these (and any other third-party assemblies you might be using) are copied locally, and get uploaded as part of our install package. The assemblies in question are:

  • System.Web.MVC
  • System.Web.Helpers
  • System.Web.WebPages
  • System.Web.WebPages.Razor
  • Microsoft.Web.Infrastructure

These last three aren’t in the reference list by default, so you’ll need to add them. They will be loaded dynamically when a page is requested (WebPages is in the <compilation> section of the web.config file.) Right click on each assembly reference in solution explorer, view the properties, and change “copy local” to true.

Now we can deploy to the cloud!

loavpftn