It seems I get 5-6 emails per week asking me how to move an existing ASP.NET MVC Web application to the Windows Azure environment. I have a short list of steps I’ve been copying and pasting into my responses, but I thought I’d take a couple of minutes to expand on those bullet points and make my answer a little more permanent by putting it on my blog.
Step 1 – Make sure you have the latest Windows Azure SDK for .NET installed. You can get it here: https://www.windowsazure.com/en-us/develop/net/.
Step 2 – Open your ASP.NET MVC project in Visual Studio. Here’s what mine looks like:
Step 3 – Add a Windows Azure Cloud Service to the solution
Here’s where we actually have to start doing some work.
First you’ll need to right-click on your solution and select Add and then select New Project
In the Add New Project dialog make sure the target framework is set to .NET Framework 4, select Cloud project types, then select Windows Azure Cloud Service, give the new project a name and click OK.
In the New Windows Azure Cloud Service dialog, don’t add any roles, just click OK.
You should end up with a solution that looks something like this:
You’ll want to make sure your Windows Azure Cloud Service project is set as the StartUp project for the solution. If the title of the Windows Azure Cloud Service project is bold in Solution Explorer you’re good to go. If it isn’t, simply right-click the project and select Set as StartUp Project.
Step 4 – Adding a Web Role
We’re almost done. The last thing we need to do is associate our current ASP.NET MVC application with the Windows Azure Cloud Service project.
Start by right-click the Windows Azure Cloud Service project and selecting Add, then select Web Role Project in solution…
In the Associated with Role Project dialog, select your ASP.NET MVC project and click OK.
Your ASP.NET MVC application should now appear as a Role in your Windows Azure Cloud Service project.
Run your application and note the URL.
If everything was done correctly, your URL should be http://127.0.0.1:81/. If it is your running in the Windows Azure Compute Emulator, which means you were successful!
If you’ve made it this far you know that there were really only two steps involved in the process, and those weren’t even that difficult. Keep in mind that just because it’s easy to convert your ASP.NET MVC application to a Windows Azure Cloud Service does not mean that it will just work in the Windows Azure environment. There are a number of things to consider when moving to the Windows Azure Platform as a Service (PAAS) model. For example, the Windows Azure environment is stateless, you need to understand the consequences of putting your application in a truly stateless environment. Questions to ask include:
- How does your application manage session? If you’re using an in-process session state provider you’ll need to change your provider. Luckily there are a number of providers available to you that leverage a number of Windows Azure technologies from table storage to distributed caching.
- How does your application store persistent data? If you’re using local disk you’ll need to make some changes as Windows Azure disks are volatile. These means that any data you write to disk is not guaranteed to be there if the virtual machine is rebooted.
Of course there are number of other things to consider from third party components required by your application, to dependencies on other systems and services that do not reside in the Windows Azure data centers, to geopolitical regulations regarding where data can and cannot reside. The point of this post was to help you get started taking your existing application to the cloud.
Now for a few bonus points:
*Bonus – you may have noticed I’m using the release candidate of Visual Studio 2012. The steps above also work with Visual Studio 2010.
*Double Bonus – these steps work for versions 3 and 4 of ASP.NET MVC.
*Triple Bonus – these steps also work for ASP.NET Web Forms applications.
*Quadruple Bonus – these steps also work for ASP.NET web sites hosting WCF services.