Overview
Using Windows Azure as your Infrastructure as a Service (IaaS) platform, will enable you to create and manage your infrastructure quickly, provisioning and accessing any host ubiquitously. Grow your business through the cloud-based infrastructure, reducing the costs of licensing, provisioning and backup.
This lab will appear at one of the Microsoft Windows Azure Developer Camps hosted throughout the United States by myself or another evangelist, such as the talented Bret Stateham.
![]() |
In this hands-on Lab, you will learn how to deploy a simple ASP.NET MVC 4 Web application to a Web server hosted in Windows Azure, using SQL Server and configuring load balancing.
High Level Overview
Objectives
In this hands-on lab, you will learn how to:
- Create a Web Farm using Windows Azure Management Portal
- Configure Load Balancing in IIS
- Deploy a Simple MVC4 Application that consumes SQL Server Features
- Create a Virtual Machine with SQL Server Full-Text Search feature to be consumed by the MVC Application
Prerequisites
The following is required to complete this hands-on lab:
- A Windows Azure subscription - sign up for a free trial
Exercises
This hands-on lab includes the following exercises:
- Creating Virtual Machines for IIS
- Creating a SQL Server Virtual Machine
- Deploying a Simple MVC4 Application
Estimated time to complete this lab: 45 minutes.
Exercise 1: Creating Virtual Machines for IIS
In this exercise, you will learn how to create a Virtual Machine in Windows Azure. Then, you will configure an Internet Information Server adding roles to use later on in this lab.
Task 1 - Creating IIS Virtual Machines
In this task, you will provision a Virtual Machine and configure the Load Balancing to host an MVC4 application.
Open Internet Explorer and browse to https://manage.windowsazure.com/ to enter the Windows Azure portal. Then, log in with your credentials.
In the menu located at the bottom, select New | Compute | Virtual Machine | From Gallery to start creating a new virtual machine.
Creating a new Virtual Machine
In the Virtual Machine OS Selection page, click Platform Images on the left menu and select the Windows Server 2008 R2 SP1 OS image from the list. Click the arrow to continue.
This is an explanation
Selecting the base image for the virtual machine
Provide a virtual machine name (ie, “iisvm1”). For size, choose Small and provide a user name and password. Click the next arrow (->) to continue to the next step. Verify that the version release date is 1/23/2014.
Naming the virtual machine
On the next screen you will provide a Cloud Service DNS Name. Choose whatever name you like as long as it is unique. You will also select a region. You can leave Storage Account and Availability Set to their default values. Click the next arrow (->) to continue to the next step. Click the Checkmark to conclude the steps.
Attaching Virtual Machine to Cloud Service
It will take 8 to 10 minutes to complete the creation of the Virtual Machine. When it is completed and running, you can begin configuring it. You will now open up port 80 to allow http traffic to travel to and from the web server.
1
Once your machine is Running, you can drill down into it by clickin on the -> arrow key. You will go to the Dashboard page and then click Endpoints. Click Add Endpoint on the bottom pane.
Navigating to the Dashboard page
Once you machine is Running, you can drill down into it by clickin on the -> arrow key. You will go to the Dashboard page and then click Endpoints. Click Add Endpoint on the bottom pane.
Adding an endpoint
Choose Add a Standalone endpoint. Continue to step 2.
Adding a stand alone endpoint
Fill out the name, protocol, public and private ports. Make sure to select the checkbox create a load balanced set.
Specifying port 80 details
Provide a name for your load balanced set name field. Click on the checkbox to complete this process.
Creating a load balanced set
You will now add a second virtual machine. It will belong to the same load balanced set as the first virtual machine. In the Virtual Machine OS Selection page, click Platform Images on the left menu and select the Windows Server 2008 R2 SP1, February OS image from the list. Click the arrow to continue.
In the Virtual Machine Configuration page, set the version release date to January 23rd, 2014
Enter the Virtual Machine Name (i.e. "iisvm2"), a User Name, a Password and the Size. Click the right arrow to continue.
You will leverage the same cloud service being used by the first virtual machine that you created. Select the appropriate cloud service for the first virtual machine that you created. Click the next arrow (->) to continue to the next step.
Connecting to the previously created cloud service
Click the checkbox to complete the process of creating your second virtual machine.
Completing the creation of the second virtual machine
Before you can connect the second virtual machine to the first virtual machine through the load balancer, you need to wait until the second virtual machine is finished getting provisioned and is running.
Completing the second virtual machine
Click on second virtual machine once it is running. Click Endpoints, then select Add from the bottom menu bar.
You will now be able to connect to a load balanced set that you created in a previous step.
Adding a second endpoint
Provide a name, and choose the reconfigure the load balanced set checkbox. Click the next arrow (->) to continue to the next step. Then click the checkbox in the final step to complete the process.
Reconfiguring the load balanced set
You should see that the second virtual machine is updating.
Validating the second virtual machine
Task 2 - Configuring IIS Virtual Machines
In this task, you will configure the IIS Virtual Machines by adding the necessary roles to deploy the MVC application.
In the Portal, click Virtual Machines on the left menu.
You will see a list with your existing Virtual Machines. Select the first one you created in Task 1 and click the Connect button in the bottom bar. If you used the proposed name, this Virtual Machine should be named iisvm01.
You will be asked to download the remote desktop settings file. Click Open and log on using the credentials you defined when creating the Virtual Machine.
In the Azure Virtual Machine, open Server Manager from Start | Administrative Tools.
In the Server Manager window, select Roles node.
Server Manager
Click Add Roles link.
Adding Server Roles
The Add Roles Wizard will appear.
In the Before You Begin page, read the content and click Next.
In the Select Server Roles page, check the Application Server and Web Server (IIS). A warning will show, informing the Required Role Services that are missing. Click Add Required Features to install them and then click Next.
Add Roles Wizard
The Application Server page provides a brief introduction about Application Server's capabilities. Click Next when you complete reading it.
In the Select Role Services page for Application Server, select Web Server (IIS)Support and make sure .NET Framework 3.5.1 is selected. It will prompt a dialog warning about missing Required Role Services. Click Add Required Role Services to install them and then click Next
Add Roles Wizard
The Web Server (IIS) page provides a brief introduction about Web Server (IIS) capabilities. Click Next when you complete reading.
The Select Role Services page for Web Server (IIS) page will display the selected role services that will be installed. Click Next.
Add Roles Wizard
In the Confirm Installation Selections page, make sure the displayed services that will be installed are the ones you have selected (.NET Framework 3.5.1 support and IIS), and then click Install.
Add Roles Wizard
Note: It will take some minutes to complete the installation.
Close the Remote Desktop Connection.
Repeat this task on the second Virtual Machine to install IIS, starting from step 4. If you used the proposed name, the second Virtual Machine should be named iisvm2.
Exercise 2: Creating a SQL Server Virtual Machine
In this exercise, you will create a new Virtual Machine and learn how to install SQL Server. You will add disk images to the existing Virtual Machine in order to split the data from the logs generated by SQL Server.
Task 1 - Creating a SQL Server Virtual Machine
In this task, you will create a new Virtual Machine using the Windows Azure portal in the same Cloud App you deployed the IIS Virtual Machines.
In the menu located at the bottom, select New | Compute | Virtual Machine | From Gallery to start creating a new virtual machine.
In the Virtual Machine OS Selection page, click Platform Images on the left menu and select the Microsoft SQL Server 2012 for Windows Server 2012 or 2008 (the Server manager in this lab uses Windows Server 2008) image from the list. Click the arrow to continue.
In the Virtual Machine Configuration page, enter the Virtual Machine Name (i.e. "sqlvm01"), a User Name, a Password and the Size. Click the right arrow to continue.
Naming the SQL Server Virtual Machine
Note: Be sure to select the same region as the web server for best performance.
In the Virtual Machine Options page, leave the default values and click the button to create a new Virtual Machine.
In the Virtual Machines section, you will see the Virtual Machine you created with a provisioning status. Wait until it changes to Running in order to continue with the following step.
Note: It will take from 8 to 10 minutes for the Virtual Machine to complete the provisioning process.
Task 2 - Attaching Empty Disk Images
In this task, you will create two empty data disks and attach them to an existing Virtual Machine using the Windows Azure Management Portal. You will use these data disks to split SQL Server Data and Logs. Having the data and logs on separate disks leads to better performance.
Now, you will create and attach empty data disks to store the SQL Server logs and data files, and you will also add an endpoint. To do this, in the Virtual Machines section, select the SQL Server Virtual Machine you created in the previous task.
In the Virtual Machine's Dashboard, click Attach in the menu at the bottom of the page and select Attach Empty Disk.
Attach Empty Disk
In the Attach Empty Disk page, set the Size to 50 GB and create the Disk.
Wait until the process to attach the disk finishes. Repeat the steps 1 to 3 to create a second disk.
Open the Virtual Machine's Dashboard. You will see three disks: one for the OS and other two for Data and Logs.
Note: It might take a few minutes until the data disks appear in the Virtual Machine's dashboard within the Azure Portal.
Attached Data Disks
Finally, you need to format the disks in order to access them from the Virtual Machine. To do this, click Connect to connect to the Virtual Machine using Remote Desktop connection.
It will ask you to download the remote desktop settings file. Click Open and log on using the credentials you defined when creating the Virtual Machine.
In the virtual machine, open Server Manager from Start | Administrative Tools.
Expand Storage node and select Disk Management option.
Disks Management
The Initialize Disk dialog will appear. Leave the default values and click OK.
Right-click the first disk unallocated space and select New Simple Volume.
Disks Management
Follow the New Simple Volume Wizard. When asked for the Volume Label use SQLData.
Wait until the process for the first disk is completed. Repeat the steps 11 to 12 but this time using the second disk. Set the Volume Label to SQLLogs.
The Disk Management list of available disks should now show the SQLData and SQLLogs disks like in the following figure:
Disks Management
Note: Do not close the Remote Desktop Connection. You will use it in the following task.
Task 3 - Configuring SQL Server in the Virtual Machine
In this task, you will configure SQL Server 2012. You will create the database that will be used by the MVC4 application and add Full-Text Search capabilities to it. Additionally, you will create a SQL Server user for the MVC4 website.
Open Windows Explorer and create the following folders: F:\Data, G:\Logs and G:\Backups.
Open the SQL Server Management Studio from Start | All Programs | Microsoft SQL Server 2012 | SQL Server Management Studio.
Connect to the SQL Server 2012 default instance using your Windows Account.
Now, you will update the database's default locations in order to split the DATA from the LOGS. To do this, right click on your SQL Server instance and select Properties.
Select Database Settings from the left side pane.
Locate the Database default locations section and update the default values to point to the disks you attached in the previous task and then click "Ok".
Setting Database Default Locations
Restart SQL Server. In the Object Explorer, right-click on the server node and select Restart.
In order to enable downloads from Internet Explorer you will need to update Internet Explorer Enhanced Security Configuration. In the Azure Virtual Machine, open Server Manager from Start | Administrative Tools | Server Manager.
In the Server Manager, click Configure IE ESC within Security Information section.
Configuring IE ESC
In the Internet explorer Enhanced Security configuration, turn off the enhanced security for Administrators and click OK.
Internet Explorer Enhanced Security
Note: Modifying Internet Explorer Enhanced Security configurations is not good practice and is only for the purpose of this particular lab. The correct approach should be to download the files locally and then copy them to a shared folder or directly to the Virtual Machine.
This lab uses the AdventureWorks2012 database. Open an Internet Explorer browser and go to http://msftdbprodsamples.codeplex.com/ to download the SQL Server 2012 sample databases. Once on the page click on AdventureWorks Databases – 2008, 2008R2 and 2012 and then download Adventure Works 2012 Data File. It should be called AdventureWorks2012_Database.zip http://msftdbprodsamples.codeplex.com/downloads/get/478214. Download the file to F:\Data.
Note: The AdventureWorks2012 database can also be downloaded as a .zip file. If you choose this format, right-click the file to open its properties window and then click Unblock. Then, extract the database to F:\Data.
Add the AdventureWorks2012 sample database to your SQL Server. To do this, in the SQL Server Management Studio, locate your SQL Server instance node and expand it. Right click the Databases folder and select Attach.
Attaching the database
In the Attach Databases dialog, press Add. Browse to the data disk and select the Adventure Works 2012 data file.
Select the AdventureWorks2012 Log entry and click Remove.
Removing AdventureWorks2012 Log entry
Press OK to add the database.
In the Databases folder, locate the new AdventureWorks2012 database and explore its tables.
AdventureWorks Sample Database
Expand Storage node within AdventureWorks2012 database, right-click Full Text Catalogs folder and select New Full-Text Catalog.
Note: You are creating a Full Text Catalog for the database that will be used later by the MVC application.
Create New Full-Text Catalog
In the New Full-Text Catalog dialog, set the Name value to AdventureWorksCatalog and press OK.
Create New Full-Text Catalog
Check that the Full-Text Catalog you created appears in the Full-Text Catalogs folder.
Create New Full-Text Catalog
Right-click AdventureWorksCatalog and select Properties. In the Full-Text Catalog Properties dialog, switch to Tables/Views page.
Add the Production.Product table to the Table/View objects assigned to the Catalog list. Then, check the Name column and click OK.
Create New Full-Text Catalog
Add a new user for the MVC4 application you will deploy in the following exercise. To do this, expand Security folder within the SQL Server instance. Right-click Logins folder and select New Login.
Creating a New Login
In the General section, set the Login name to CloudShop. Select SQL Server authentication option and set the Password to Azure$123.
Note: If you enter a different username or password than those suggested in this step, do not forget in the next exercise to update the web.config file of the MVC4 application to match those values.
Unselect Enforce password policy checkbox to avoid having to change the password the first time you log on, and set the Default database to AdventureWorks2012.
Creating a New Login
Click User Mapping on the left pane. Select the map checkbox in the AdventureWorks2012 database row and click OK.
Mapping the new User to the AdventureWorks Database
Expand AdventureWorks2012 database within Databases folder. In the Users folder under Security, double-click CloudShop user.
Select the Membership page, and select the db_owner role checkbox for the CloudShop user and click OK.
Adding Database role membership to CloudShop user
Note: The application you will deploy in the next exercise uses Universal Providers to manage sessions. The first time the application runs, the provider will create the Sessions table within the database. For that reason, you are assigning a db_owner role to the CloudShop user. Once you run the application for the first time, you can remove this role as these permissions will not be needed.
Now, enable Mixed Mode Authentication to the SQL Server instance. To do this, in the SQL Server Management Studio, right-click the server instance and click Properties.
Click Security in the left side pane and then select SQL Server and Windows Authentication mode under Server Authentication section. Click OK to save changes.
Restart the SQL Server instance. To do this, right-click the SQL Server instance and click Restart.
Close the SQL Server Management Studio.
In order to allow the MVC4 application access the SQL Server database you will need to add an Inbound Rule for the SQL Server requests in the Windows Firewall. To do this, open Windows Firewall with Advanced Security from Start | Administrative Tools.
You could also execute c:\Windows\System32\WF.msc
Select Inbound Rules node, right-click it and select New Rule to open the New Inbound Rule Wizard.
Creating an Inbound Rule
In the Rule Type page, select Port and click Next.
New Inbound Rule Wizard
In Protocol and Ports page, leave TCP selected, select Specific local ports, and set its value to 1433. Click Next to continue.
New Inbound Rule Wizard
In the Action page, make sure that Allow the connection is selected and click Next.
Protocol and Ports
In the Profile page, leave the default values and click Next.
In the Name page, set the Inbound Rule's Name to SQLServerRule and click Finish
New Inbound Rule Wizard
Close Windows Firewall with Advanced Security window.
Note: Make sure the Named Pipes and TCP/IP protocols are enabled for the Server Instance. You can verify this by going to the SQL Server Configuration Manager and within SQL Server Network Configuration node check that these protocols' status are set to enable.
Remember to restart the SQL Server instance after enabling a protocol.
Close the Remote Desktop Connection.
Exercise 3: Deploying a Simple MVC4 Application
In this exercise, you will learn how to deploy a simple ASP.NET MVC4 application in the IIS of the Azure Virtual Machine you have previously configured.
Note: To make this solution highly available, you need to configure the SQL Servers in an availability set and set up SQL Server Mirroring between the instances.
Task 1 - Deploying a Simple MVC4 Application
In this task, you will deploy the MVC4 application to the IIS Virtual Machines.
In the Azure Portal, Click Virtual Machines on the left menu.
You will see a list with your existing Virtual Machines. Select the first one you created in Exercise 1 and click Connect. If you used the proposed name, this Virtual Machine's should be named iisvm1.
You will be prompted to download the remote desktop client. Click Open and log on using the Admin credentials you defined when creating the Virtual Machine.
You need to install .NET Framework 4.0 before deploying the MVC4 application. In order to do that, you will enable downloads from IE update Internet Explorer Enhanced Security Configuration.
- In the Azure Virtual Machine, open Server Manager from Start | Administrative Tools.
In the Server Manager, click Configure IE ESCwithin Security Informationsection.
Internet Explorer Enhanced Security
In the Internet explorer Enhanced Security dialog, turn off enhanced security for Administrators and click OK.
Internet Explorer Enhanced Security
Note: Modifying Internet Explorer Enhanced Security configurations is not a good practice and it only for the purpose of this particular lab. The correct approach would be to download the files locally and then copy them to a shared folder or directly to the Virtual Machine.
Now that you have permissions to download files, open an Internet Explorer browser session and navigate to http://go.microsoft.com/fwlink/?linkid=186916.
- Download and install .NET Framework 4.0.
- This is the standalone installer.
Installer for .NET 4.0
Note: Depending on which version you installed in previous steps, the .NET Framework may already be on your system.
Once .Net Framework 4.0 installation finishes, open wwwroot folder located at C:\inetpub and copy the file CloudShop.zip located in Source\Assets\CloudShop folder of this lab. To do this, copy CloudShop.zip (Ctrl + C) and paste it (Ctrl + V) in the Virtual Machine's wwwroot folder. Extract all files to C:\inetpub\wwwroot\CloudShop folder.
Note: You can also download the Cloud.zip here. http://1drv.ms/1cXdDE7
wwwroot folder
Verifying port 1433 is open
- You will need to verify port 1433 is open on virtual machine. You will now open up port 1433 to allow SQL Server traffic to travel to and from the the virtual machine hosting SQL Server.
- Return back to the portal. Verify your machine is Running. You can drill down into it by clicking on the -> arrow key.
- You will go to the Dashboard page and then click Endpoints. Click Add Endpoint on the bottom pane.
- Choose Add a Standalone endpoint. Continue to step 2.
- Provide a name and specify port 1433 for the public and private ports. Click the checkmark to complete the process.
Opening port 1433
Open with Notepad the Web.config file located in C:\inetpub\wwwroot\CloudShop. Replace the connection strings placeholder with the name of your SQL Server (by default, is the Virtual Machine's name).
XML<?xml version="1.0"?><!--For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=169433 --><configuration><configSections><!--For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --><sectionname="entityFramework"type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"requirePermission="false"/></configSections><connectionStrings><addname="AdventureWorksEntities"connectionString="metadata=res://*/Models.AdventureWorks.csdl|res://*/Models.AdventureWorks.ssdl|res://*/Models.AdventureWorks.msl;provider=System.Data.SqlClient;provider connection string="Data Source=[your server name].cloudapp.net;Initial Catalog=AdventureWorks2012;Persist Security Info=True;User ID=CloudShop;Password=[secret];multipleactiveresultsets=True;App=EntityFramework""providerName="System.Data.EntityClient"/><addname="DefaultConnection"connectionString="Data Source=[your server name].cloudapp.net;Initial Catalog=AdventureWorks2012;Persist Security Info=True;User ID=CloudShop;Password=[secret];MultipleActiveResultSets=True"providerName="System.Data.SqlClient"/></connectionStrings><!-- the rest of the file omitted for clarity --></configuration>
Open the Internet Information Services (IIS) Manager from Start | Administrative Tools. After creating a web folder and copying an MVC application to it, you need to Convert it to a Web Application.
In the Connections pane, expand Default Web Site within your IIS Server's node. You will see the CloudShop folder you copied in the wwwroot folder.
IIS Manager
Right-click CloudShop folder and select Convert to Application.
IIS Manager - Convert to Application
In the Add Application dialog, click OK.
Add Application dialog
Finally, select the Application Pools node and double-click DefaultAppPool application pool.
Updating Default Application Pool
In the Edit Application Pool dialog, change the .Net Framework version to v4.0 and click OK.
Editing Application Pool
Now, the DefaultAppPool's .Net Framework should be v4.0 instead of v2.0.
Updating Default Application Pool
Close the Internet Information Server (IIS) Manager window.
Close the Remote Desktop Connection.
Repeat this task in the second Virtual Machine you created in Exercise 1 -Task 1. If you used the proposed name, this Virtual Machine should be named iisvm2.
Verification
In this task, you will test the Cloud Shop MVC4 application you deployed in the previous task.
In your local machine, open Internet Explorer.
Go to http://[YOUR-SERVICE-NAME].cloudapp.net/CloudShop. The Service Name is the one you used when creating the IIS Virtual Machines (you can also check it in the Azure Portal, within Virtual Machine's dashboard).
- The address below is just there for demo purposes. You will not have iiscloudservice01.
MVC4 Application running in the Web Farm
In the Search box, write Classic and click Search. It will show all the products that have a product name that match the search criteria.
Searching Products
Summary
In this hands-on Lab, you have learnt how to deploy a simple ASP.NET MVC 4 Web application to a Web server hosted in Windows Azure, using SQL Server and configuring load balancing.
I opened up two instances of the app, simulating two users. The apps appropriately kept their own copy of the shopping card. It appeared that the load balancer was working as well as my ability to maintain two shopping carts.