This entry demonstrates how to host a C# web application in Microsoft Windows Azure Platform. This also provides information on various tools and processes involved in order to accomplish this. The requirement is to host a web application developed in .Net framework 3.5 which uses SQL server 2008 database.
The following tools were used for the purpose:-
- Windows Azure Account
- Visual Studio 2010 Express Web Edition
- SQL Express 2008 R2
- Windows Azure SDK
Hosting an application in Windows Azure required the following steps:-
FIRST step was to set up of Windows Azure account using my hotmail id and configuring the hosted service. I had selected pay-as-you-go plan using my credit card information. After registering the account and validating it through Microsoft customer care, my azure control panel got ready to use after 20 minutes. My aim was to host a web application so I created a hosted service by clicking the icon “New Hosted Service” in the upper left corner of the Windows Azure Hosted Service control panel. The wizard was very simple to understand and get my task done. Now since the application I had host requires a database I had created one database in Windows Azure using the minimal configuration. The great feature of the SQL Azure is that we can access and operate the database from anywhere.
SECOND, I had to convert the present application locally which was created in .Net framework 3.5 to .Net framework 4.0 and to add the ASP MVC3 web role to the application and to create a database corresponding to the application locally and restore the database to SQL Azure. In order to accomplish this I installed Visual Studio 2010 Express and SQL Server 2008 R2 Express and Windows Azure SDK, which can be downloaded freely (registration is required if anyone want to use it for more than 30-days) and Windows Azure SDK from Microsoft site. After the conversion I added the MVC3 web role to the project and upon building the locally, I encountered the namespace issue with all the project files, which got resolved by adding the proper namespace (in aspx.cs files) and updating the “CodeBehind” and “Inherits” entries (in .cs files) accordingly in each of the project files. After resolving the issues with local building of the project I planned it to build using the database hosted in azure too! In order to do that I created the script of the local database of the application and restored it in the SQL Azure. The web.config file of the application was updated with the SQL Azure database connection string. The build was successful!
THIRD, as the application was building properly using both the local database and SQL Azure, time is now to deploy it in Azure platform. The deployment of the project requires only 2 files which is an output of the project’s publish command using visual studio i.e. .cspkg (package location) and .cscfg (Configuration file). I configured the Azure Hosted Service instance with these files and given a proper name. Since it is the project’s first deployment I selected to deploy it in staging environment. The deployment went successful and the project was running fine. Now I changed the deployment option to production environment.
FINALLY, I configured the DNS settings of my registered domain to point to Azure Cloud application hosted service’s URL so that anyone can read and remember the URL of the application easily!