How to take an ASP.NET site to the Cloud in about 15 minutes

Windows Azure is Microsoft’s “Platform as a Service” or PaaS offering in the cloud space that provides developers with an updated, scalable and durable environment to deploy applications to. Over the last year I’ve spent quite a bit of time working with the Windows Azure Boot Camp crew to help people learn about the cloud, why it’s important, and how to get started designing and building solutions that leverage these benefits. In this post I’d like to share a quick overview of how to take an existing application to Windows Azure quickly and easily.

Get the tools. The right tools make any job easier, whether it’s cabinetry, construction or writing code. Visual Studio 2010 has tools that can be added that empower the developer to work with the cloud. You can get these a couple ways. The old way is to go to Microsoft’s download center and pull down the individual SDK files. You have to know whether you’ve got the right pre-reqs or not and the responsibility is yours to run things in the right order. But there is an easier way. Microsoft’s Web Platform Installer (or WebPI) includes not just a gallery of applications you might be interested in, but also the tools and frameworks that make it easy. All you have to do is download and run the installer from https://aka.ms/azuresdk and select the September 2011 Tools and click Install. The installer then figures out all the dependencies and batches them together into a single EULA and runs the complete install for you.

image

Open your existing Web Project. You’ll want to run Visual Studio as an Administrator by either right clicking the icon and selecting “Run as Administrator” or by holding the CTRL+SHIFT and double clicking the Visual Studio Icon. The reason for running VS as admin is that to create or add an Azure project the tool wants to ensure that it can run the solution from the local emulator, which requires connecting across process boundaries. This requires elevated rights. Once you have Visual Studio 2010 open, select the existing project. Mine looks like this:

image

You will add a Cloud Project to the existing solution by adding New Project, selecting Cloud as the type, then adding the Windows Azure Project to existing Solution. This works from both VB and C# projects.

image

Next you get prompted to select a role type to add. In the current release the types of roles we could add include ASP.NET Web Roles (aka Web Forms), MVC 2 and 3, WCF Service Role, Silverlight RIA App, and a Worker Role. Since we already have an existing web site you don’t need to add anything. We’ll add our existing site in the next step.

image

This will add a new project to our solution that includes a Service Definition file and a couple configuration files. The Service Definition file describes the endpoints, size of role, bindings, startup tasks and other information about how we want the web role to run. There is also a Roles folder which is currently empty.

Add our existing site to the Cloud Project. We’ll add our existing site to cloud project by right clicking and selecting add a Web Role from the current solution. This will update the Service Definition file to include information about the web role we added.

image

NOTE: For my example I’m taking a simple static web site and moving it to the cloud. I am not looking at the data connections or strategy for how we want to scale up and out for performance. We’ll focus on these issues in a later post.

At this point we could test our solution by running it in the emulator by simply pressing F5. The Windows Azure Emulator that is installed with the SDK and Tools for Visual Studio would start up and allow us a debug attached environment to see how well it runs.

Create the Package. By right clicking on the MyCloud project you get a menu of options for packaging and publishing your solution. I showed how to configure Visual Studio to publish directly to Windows Azure in another post, but for now we’re simply going to create the package. We’ll select the Service Configuration for Cloud and Release and then click Package to build the files necessary to publish our application in Windows Azure. Visual Studio will run CSPACK to compile the files and then open an explorer windows to where the package and configuration files are written to. You’ll use this file location next when we create a hosted instance.

image   image

Create a Hosted Instance. Next we will open a browser and go to https://windows.azure.com. I’m assuming you’ve already got a subscription to work with, if not you can get an Azure Trial (which includes 90 days of Azure – 750 hours Small Compute Instance, 20 GB storage, 1 GB SQL Azure database and more), or if you have an MSDN subscription you can activate your benefits. Log into the portal and you should see your subscription data loaded into the Silverlight application. Click on the Ribbon button “New Hosted Service” to create a new deployment.

image

This opens a dialog that collects information about your new service. Here we’ll select a name for the service, enter a unique name for the URL prefix, pick a data center to deploy to, then enter a deployment name. Next browse to the location you built the package files and add them for the Package Location and the Configuration File. We’ll worry about certificates another time, but for now click OK and the package will be deployed and run in the cloud.

image

If this is your first deployment and you did not edit the number of instances to create to be 2 or more you may see a warning that the SLA criteria are not being met. For now we’ll ignore this warning, but in a production scenario you would want to either edit your configuration file directly to include 2 or more instances or do it from Visual Studio before you create the package. This is done from the properties pages of the Web Role in the Cloud Project.

image

Run App in the Cloud. What happens next is that the package files you created are uploaded to Windows Azure and the Azure Fabric Controller will allocate resources on which to run it. A Deployment is created and instances under the deployment depict the status of your site. Azure will go thru several states, from uploading the files, to initializing the machine (s), to running thru the startup routines, to making the environment ready for use. Once it’s ready you can browse to your site in the cloud.

image

Typically I’ve seen the startup time to be between 5-10 minutes although it can be longer or shorter depending on the speed of your connection (for upload) and what else is going on at your selected data center. If you’re interested in more information about how to get started in the cloud quickly check out the Windows Azure Boot Camp site for a schedule of live events, or watch an online webcast where we go thru the process at wabcWebcasts2011.

Happy Coding!