Export (0) Print
Expand All
6 out of 14 rated this helpful - Rate this topic

Configure a Web Role for Multiple Web Sites

Updated: November 13, 2013

By using the Sites element within the service definition file, ServiceDefinition.csdef, you can configure your web role to support multiple web sites and web applications. This is accomplished using the sites, applications, and virtual directories features in Internet Information Services (IIS) 7.0. These features enable each web role in Azure to support configuration for multiple web sites and applications.

New projects are created with the Sites element by default. Within the Sites node, you can add additional ASP.NET web sites or web applications by adding Site nodes.

Azure does not impose a security boundary between the sites and applications that are running within the role. The only configurable boundary that is available is one between Administrative and non-Administrative users. This can have implications when you are considering the security of the web sites. For example, if one user’s web site is using an HTTPS certificate for the hosted service, another user’s web site in the same web role would be able to access the HTTPS certificate for that site.

If you must host different web sites on one web role with several users, you should use the VM role and configure the IIS isolation boundaries that are necessary to provide appropriate security for each site.

For additional information about how IIS manages sites, see Configure a Web Server to Serve Content (IIS 7.0).

For a step-by-step example of configuring multiple web sites in a web role, see Exercise 1: Registering Sites, Applications, and Virtual Directories in the Windows Azure Platform Training Course.

For descriptions of the XML elements in the ServiceDefinition.csdef file, see Azure Service Definition Schema (.csdef File).

noteNote
The Sites element is only available by using the Windows Azure SDK version 1.3 or above.

The following steps assume that you have installed Visual Studio 2010 and the Windows Azure tools for Visual Studio, and you have created a cloud project with one web role, to which you will add additional web sites.

Use the following procedures to configure multiple web sites and web applications in a web role on Azure.

Use the following procedures to configure additional web sites in a web role on Azure.

  1. In Visual Studio, right-click your solution in Solution Explorer, and then click Add.

  2. Click New Web Site....

  3. Fill in the wizard to create the new web site project.

  4. Right-click the new web site project in Solution Explorer, and then click Publish Web Site....

  5. In the Publish Web Site dialog box, click OK.

  1. Open the ServiceDefinition.csdef file for the cloud project.

  2. Under the Sites element for the WebRole, copy the following XML code after the existing Site element.

    <Site name="web-site-name" physicalDirectory="relative-location">
      <Bindings>
        <Binding name="binding-name" endpointName="endpoint-identifier" hostHeader="custom-domain-name" />
      </Bindings>
    </Site>
    
  3. Modify the name and physicalDirectory attributes of the Site element to reflect the name of your new web site and the location of your web site project.

    TipTip
    The physicalDirectory attribute value is relative to the location of the service configuration file. If you copy the XML code, you must modify the physicalDirectory attribute value to reflect the folder structure of your application. For example, if your ServiceConfiguration.csdef file is located at C:\projects\CloudProject\ServiceConfiguration.csdef and the folder containing your new web site is located in C:\projects\NewWebSite then the relative path in the physicalDirectory attribute would be "..\NewWebSite"

  4. Modify the name and endpointName attributes of the Binding element to match the existing site.

  5. Modify the hostHeader attribute to specify a host name for your new web site on the original endpoint. The new web site will be addressed using the name in the host headers to distinguish it from other sites. For local testing, modify your Hosts file to point the host name to the loopback address, 127.0.0.1.

  1. Open the ServiceDefinition.csdef file for the cloud project.

  2. Under the Sites element for the WebRole, copy the following XML code after the existing Site element.

    <Site name="web-site-name" physicalDirectory="relative-location">
      <Bindings>
        <Binding name="binding-name" endpointName="endpoint-identifier" />
      </Bindings>
    </Site>
    
  3. Modify the name and physicalDirectory attributes of the Site element to reflect the name of your new web site and the relative location of your web site project.

  4. Add a new InputEndpoint element to the Endpoints collection. Modify the name attribute to a new value, set the protocol attribute to http or https, and set the port attribute to the port number that will be used to access the new web site.

      <InputEndpoint name="new-endpoint-identifier" protocol="http-or-https" port="port-number" />
    
    
  5. Modify the name and endpointName attributes of the Binding element to match the new endpoint.

When you create a web role, you create a cloud project with one web role that is configured as a web site. The following procedure explains how to add additional web sites running the same web application code to the web role.

  1. Open the ServiceDefinition.csdef file for the cloud project.

  2. Under the Sites element for the WebRole, copy the following XML code.

    <Site name="application-name" physicalDirectory="relative-location">
      <Bindings>
        <Binding name="binding-name" endpointName="endpoint-identifier" hostHeader="custom-domain-name" />
      </Bindings>
    </Site>
    
  3. Set the physicalDirectory attribute of the Site element to the path of the web role project relative to the service configuration file, and the name attribute to a new name for the web application. Use the hostHeader attribute of the Binding element to specify a host name for your additional site on the original endpoint.

  4. For local testing, modify your Hosts file to point the host name to the loopback address, 127.0.0.1.

When you create a web role, you create a cloud project with one web application that is configured as a web site. The following procedure explains how to add a virtual application to the web role.

  1. In Visual Studio, right-click your solution in Solution Explorer, and then click Add.

  2. Click New Project....

  3. Select a web application template and fill in the wizard to create the new web application project.

  4. Right-click the new web application project in Solution Explorer, and then click Build.

  1. Open the ServiceDefinition.csdef file for the cloud service.

  2. Under the Sites element for the WebRole, add a VirtualApplication element to the Site element for the existing web site. Fill in the name attribute with the name for the virtual application, and set the physicalDirectory attribute to the path of the web application project relative to the service configuration file.

    <Site name="Web">
       <VirtualApplication name="application-name" physicalDirectory="relative-location" /></Site>
    
  3. To access the virtual application, append the value of the name attribute to the URI of the primary website. For example, if the primary website is accessed with http://www.contoso.com/ then a virtual application named example would be accessed at http://www.contoso.com/example/.

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.