by Jim White (Director of Training and Instructor)
With Windows Azure SDK 1.3, you can run multiple Web Sites in a single Web role. Prior to Windows Azure SDK 1.3, each Web role ran a single Web application. This constraint was largely because Web roles were hosted in IIS Hosted Web Core where a single application was bound to a single HTTP/HTTPS endpoint. Now, Windows Azure supports full IIS capabilities allowing Web roles to support multiple Web sites and Web applications.
Create or Add Existing Web sites to a Cloud Project
Multiple Web sites and applications are accomplished using Web sites, virtual applications, and virtual directories features in IIS 7.0. You can find more information about these IIS 7 features here. Once you have a Windows Azure project with an existing Web role, you can create or add existing Web sites to the project. With the new Windows Azure Tools for Visual Studio version 1.3 (or better), there is nothing Azure-specific that needs to be done to create or add a Web site to the solution. Simply use the existing VS means of creating or adding a Web Site to the solution containing your Windows Azure project.
In this example, a virtual application and virtual directory Web sites were added to a HelloWorld project.However, without any other work, if you were to run this application in the cloud or on the Compute Emulator, only the HelloWorld Web role would be accessible. Neither of the two new Web sites could be reached.
Making Web Sites Accessible
In order to incorporate the Web sites into the Windows Azure project, new elements need to be added to the service definition file (.csdef). Specifically, you need to add a new <VirtualApplication> and <VirtualDirectory> elements for the Web sites added to the solution. Unfortunately, there are no tools to accomplish this task at this time. You must open the service definition file and add the XML necessary to define your Web sites. When you open the service definition file, you find there is an existing <Site> child element to the <Sites>.
This site is for the existing Web role endpoint ? the HelloWorldWebRole in this example. Add child <VirtualApplication> and <VirtualDirectory> elements to the <Site> in order to add virtual application and virtual directory Web sites. The example virtual application and virtual directory from above are added here.
Now the Web sites (virtual application and virtual directory) can be accessed through Azure or the Compute Emulator. Simply use the virtual application name with the Web role URL to access the virtual application Web site. Use the virtual directory name and resource name with the Web role URL to access a resource in the virtual directory.
Using the Old Hosted Web Core
You can still run in the old-style Hosted Web Core mode. This limits the capabilities of your application ? such as having multiple Web sites per role. To run in Hosted Web Core versus full IIS 7, simply remove the <Sites> element from the service definition file.
A better understanding of the differences (and impact) of running Full IIS 7 versus running in Hosted Web Core can be found in a blog post by the Windows Azure Team here.
I found the following MSDN articles and blog posts to be helpful in learning about Multiple Web Sites with Azure.
I recently completed writing the update (version 3) of Intertech’s Complete Windows Azure class. Here’s a list of what’s new in the class.
- All text and labs have been updated to cover the new Windows Azure Developer Portal
- All labs have been updated to use Windows Azure SDK ver. 1.3
- A chapter on Windows Azure Administration was added to include material on subscriptions, how to set up and utilize co-administrators, understanding Windows Azure OS Family and Guest OS, Remote Desktop to Windows Azure virtual machines, and more.
- A new lab was added to try Remote Desktop into an Azure virtual machine.
- Lab material was added to explore co-administration of Windows Azure.
- A new lab was added to explore SQL Azure and tools for creating and exploring databases in the cloud.
- Lab material was added to explore how to see how to publish to Azure directly through Visual Studio (bypassing the Developer Portal).
- Material was added to explore Web roles with multiple Web sites.
- All labs and text have been updated to include Visual Basic code samples and lab solutions (in addition to C# samples and lab solutions).
- An explanation of the new extra small VM and use of the extra small VM in labs.
- A quick look at the VM Role and how it relates to the other parts of Windows Azure Compute.
- A look at using IntelliTrace in Visual Studio to debug and examine applications running in the cloud.
Click here for more details on Intertech’s Complete Windows Azure class. If your team needs help implementing an Azure solution, contact Ryan McCabe (Intertech’s account representative for Azure) at email@example.com. As always, I also encourage you to register with the Virtual Azure User Group (azureug.net). We meet monthly in virtual space and share our knowledge and experiences on Azure.