Sunday 25 March 2012

Publishing Multiple Sites, Sub-Sites & Virtual Directories in a single Azure Web Role - Part 2


In previous post, we had seen how to deploy Web Role with multiple Sub Sites. In this post, I am planning to deploy Web Role with Virtual Directories.

Creating the Project

Step 1: Create a Cloud Project in Visual Studio.
Step 2: As we are running multiple sites in a single role, we will keep a sample message in the Default.aspx page for understanding which site is running.
Open the Default.aspx and modify the page content to Web Role Application.
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    Web Role Application
</asp:Content>
Step 3: Run the application and verify the content.

Adding a New Virtual Directory

Step 1: To add Virtual Directory, right click the solution and select Add -> New Web Site.
Step 2: Visual Studio will open Add New Web Site window. Select ASP.NET Empty Web Site template and specify the Web location.
The location can be either in the solution folder or any other location in the system. When we select the location in solution folder, we can specify as relative path otherwise it can be specified directly physical path in the configuration file.
Step 3: We need to add some files in the virtual directory (i.e., in the referred physical path). So open the folder in Windows Explorer and copy some files in the directory (or directly copy files in the Visual Studio under VirtualDir project).
Note: I have created a sub folder (Image) and copied an image file.
Step 4: Now we required to modify the configuration file for accessing the Virtual Directory from browser. So open the ServiceDefinition.csdef file and add a VirtualDirectory under Site node.
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="MultiVDir" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole name="WebRole" vmsize="Small">
    <Sites>
      <Site name="Web">
        <VirtualDirectory name="VirtualDir" physicalDirectory="../VirtualDir" />
        <Bindings>
          <Binding name="Endpoint1" endpointName="Endpoint1" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="Endpoint1" protocol="http" port="80" />
    </Endpoints>
    <Imports>
      <Import moduleName="Diagnostics" />
    </Imports>
  </WebRole>
</ServiceDefinition>
Step 5: Now you run the application and verify the output. By default the browser will open the main application.
Step 6: You can access the files stored under the Virtual Directory, add the Virtual Directory name and the file name at the end of the url.


In the next post, we will see how to configure for running multiple sites in a single Web Role.

The other links on Publishing Multiple Sites, Sub-Sites & Virtual Directories in a single Azure Web Role:
  1. Publishing Multiple Sites, Sub-Sites & Virtual Directories in a single Azure Web Role - Part 1
  2. Publishing Multiple Sites, Sub-Sites & Virtual Directories in a single Azure Web Role - Part 2
  3. Publishing Multiple Sites, Sub-Sites & Virtual Directories in a single Azure Web Role - Part 3


2 Responses to “Publishing Multiple Sites, Sub-Sites & Virtual Directories in a single Azure Web Role - Part 2”

  • Anonymous says:
    6 August 2013 at 23:35

    Is it possible to specify physicalDirectory as C:\newFolder

  • Thirumalai M says:
    7 August 2013 at 19:18

    Hi, The reference always with relative path and not physical path. When you publish to Azure, you no need to worry the physical location.

    Good to go with relative path only.

Post a Comment