Export (0) Print
Expand All

Configure a Web Role for Multiple Web Sites

Updated: May 9, 2014

By using the Sites element within the service definition file, ServiceDefinition.csdef, you can configure your web role to support multiple websites 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 websites and applications.

New projects are created with the Sites element by default. Within the Sites node, you can add additional ASP.NET websites 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 websites. For example, if one user’s website is using an HTTPS certificate for the hosted service, another user’s website in the same web role would be able to access the HTTPS certificate for that site.

If you must host different websites 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 websites 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 websites.

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

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

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

  2. Click New Website....

  3. Fill in the wizard to create the new website project.

  4. Right-click the new website project in Solution Explorer, and then click Publish Website....

  5. In the Publish Website 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 website and the location of your website 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 website 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 website on the original endpoint. The new website 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 website and the relative location of your website 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 website.

      <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 website. The following procedure explains how to add additional websites 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 website. 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 website. 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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft