Add Windows Azure Web Role to your MVC project

The June 7th update to Windows Azure introduced two new services (Windows Azure Websites and persistent VMs), or Web Role and Worker Role:

Azure Web Role and Worker Role

Image 1 – Web Role and Worker Role

 

In this article I will show you how to add new Web Role to your project. As a project we will use simple MVC 4 application. I am using Visual Studio 2012. In second image we can see a tree of our new MVC 4 application:

 

Azure Simple MVC 4 project

Image 2 – Simple MVC 4 project

 

We can run our MVC application in local machine and see that it works:

Azure Run site in local machine

Image 3 – Run site in local machine

 

In the next step we should add Web Role to our project. For this right click on solution and select “Add - New Project ..”. In occurred window select “Visual C# - Cloud”, enter name (in my case this is WindowsAzureWebRole) and press Ok. Then a new window will occur. Select suitable Web Role for your project and press Ok:

Type of Web Role in Azure project

Image 4 – Type of Web Role

 

You will receive new project in your solution:

Windows Azure project in solution

Image 5 – Windows Azure project in solution

 

In the next step we should configure our Web Role to get access to publishing this MVC application on Windows Azure. First – we need to add existing MVC Application to our Web Role. For this right click on “Roles – Add - Web Role Project in solution .. ” and select existing MvcApplicationWebRole:

Add existing MVC application as Web Role to Azure project                                                                                              

Image 6 – Add existing MVC application as Web Role

 

In the next step we should configure our Web Role. For this right click on your web role (In folder Role right click on MvcApplicationWebRole). A new window will occur (image 7). You can configure here virtual machine size (Instances – VM size). We leave it as it is. Also, we can select secure Http protocol. In this case, our site will use secure connection:

Web Role settings

Image 7 –Web Role settings

 

Then we need to specify the storage account for our Web Role. So in panel Diagnostics press on button “..”. A new window will occur (image 7). In this window select “Your subscription”. You should have a subscription for windows azure. It could be a trial. You can get a subscription to Windows Azure by this link. So then click on “Download Publish Settings”. It will bring you to address. After redirect to this site, Publish settings will be downloaded automatically. Save it on a disc. Then click button Import (image 8) and select downloaded publish settings. Then press Ok:

Set Windows Azure subscriptions

Image 8 – Set Windows Azure subscriptions

 

In next step we need to add a new certificate to our Web Role. But first we should create new Azure service and add a certificate to this Service. For this we should go to Manage Windows Azure by link and press button New (image 9). Then press button Create Cloud Service:

Create new Azure Cloud Service

Image 9 – Create new Cloud Service

 

Then we should add a certificate for this new service. So we need to go on the tab to this new service Certificates of this Service and click button Upload. A new window will occur. So select a certificate from your local disc and enter a password. Then press button Ok (Image 10). I will show how to generate certificate in some next topics.ґ

Add certificate for this new service in Azure project

Image 10 – Add certificate for this new service

 

After this copy thumbprint of this certificate. We will need this thumbprint on next step.

Then go back to your Visual Studio.

Click on tab Certificates (image 6). A new window will occur (image 11). Simply click on button Add Certificate. Specify new name for this certificate (in my case it WindowsAzureWebRole.Certificate), as Thumbprint paste copied on previous step thumbprint as a value:

New certificate for Web Role

Image 11 -  New certificate for Web Role

 

Now we can publish our project to Windows Azure Service. For this right click on WindowsAzureWebRole and select Publish. New window will occur:

Windows Azure service - Publish settings

Image 12 – Publish settings.

 

Click next. On tab Settings in drop down Cloud Service select service that was created before in Manage Windows Azure: