Moving your ASP.NET Application to Windows Azure – Part I

Earlier I had written 2 posts – Taking your Northwind Database to SQL Azure and binding it to an ASP.NET GridView Part I and Part II .  I thought, I will complete the series with a post on moving your ASP.NET Application as well to Windows Azure making it a truly cloud based application.

Before we start, there are a bunch of things that you would need to do.  First and foremost, you would need a Token for Windows Azure.  You can request for a free token for Windows Azure from here after providing your Live ID and a few more details.   I am not aware of the current time it takes for receiving a token but in the past it used to be 24 hours.

Similarly, if you want to have SQL Azure Tokens, you can get it from here and then login to https://sql.azure.com to redeem the token once you receive the same.  (if you had migrated your SQL Database to SQL Azure as per my earlier posts, you would have done these already)

Once you receive the tokens for Windows Azure, you would need to visit the http://lx.azure.microsoft.com/ and sign in with your Live ID that you used for registering for the tokens.  Once you login, you would be able to see a screen as below

image

Since you haven’t claimed the tokens, there won’t be any projects listed here.  You can click on “Account” tab and click on “Manage my Tokens” in the bottom to claim the tokens for Windows Azure.  With this token you can create 1 hosted services account and 2 blob storage accounts.

And, for development purposes, you would require Visual Studio 2008 SP1 and the Windows Azure Tools for Visual Studio 2008 SP1.  You can download the tools from here

For the rest of the post, I am going to assume that you received the tokens for Windows Azure and SQL Azure and have already migrated the northwind sample database to SQL Azure and did the configuration steps as per Part I and Part II of my posts as well as created the web application with a simple gridview that binds to the SQL Azure database.

Once you login to the portal http://lx.portal.azure.com and click on the Project you will get a screen similar to the one below

image

In the above, you can see that, I already have a blob account by name “harishblobs” that I would use to store heavy data such as video etc., But the point of your interest would be the “New Service” link that is on the top.  You would need this when you are migrating your ASP.NET Application in the steps to follow.

If all is done as per my earlier steps, you have your ASP.NET Application with a simple webform that has a GridView.  The GridView is bound to a SQL DataSource and the SQL DataSource initially was configured to the use the local database instance of northwind database and thereafter, you had changed the connection string pointing it to the SQL Azure database.

The next step is to add a Cloud Project to your ASP.NET Application.  In Visual Studio 2008, click on “File – Add – New Project” and choose “Cloud Service”

image

This would provide a screen to chose the Role type as below

image

Since we already have an existing ASP.NET Application,we just have to click “Ok” with “ASP.NET Web Role” highlighted as you see in the screen.  Make sure the “Cloud Service Solution” is blank as per the above screen.

With this step you will find that a “CloudService1” has been added to the solution and it has a “Roles” folder as well as 2 configuration files. 

Right Click on the Roles and select “Add – Web Role Project in Solution”

image

This would automatically add the existing Web Application in your solution to the Cloud project under “Roles” (you will only see a cloud project icon with the name of your existing web application – the files won’t move)

Once this step is done, you just have to build the whole solution once.  If all is well, and you run the solution, you will get the page but there would be a series of notifications as well as status messages on the Visual Studio bar in the bottom indicating the steps the tool is doing.

After a few minutes you would get an URL which is http://127.x.x.x that has your page.  Remember, we earlier had the localhost URL.  This is the Fabric Controller simulation of your application running on the cloud.  You can click on the notification area in your task bar to open the “Development Fabric UI” (The Development Fabric is something that gets installed when you install the Windows Azure SDK).  You can expand the “Service Deployments” icon in the Development Fabric and then expand the subsequent node to the see the instances running.  By default it shows 0 which indicates one instance of your application is running. You can change is number from the “ServiceConfiguration.cscfg” file in the Cloud Project and set the “Instances Count” to 3 or 4 or whatever you like.  Once you do that and re-run the solution you would get a simulation screen in the Fabric Controller as below

image

Make sure you change back the number of instances to "1" in the file above before publishing to Windows Azure, since in production, as of CTP, it supports only 1 instance. 

With this, we are all set to go the Cloud :)   Considering the length of the post, I would put the next set of steps in another post to follow. Read next post

Cheers !!!

Print | posted on Friday, December 18, 2009 1:48 AM

Comments on this post

No comments posted yet.

Your comment:

 (will show your gravatar)