1 out of 13 rated this helpful - Rate this topic

How to: Migrate and Publish a Web Application to Windows Azure from Visual Studio

To take advantage of the hosting services and scalability of Windows Azure, you might want to migrate and publish your Web application to Windows Azure. You can run a Web application in Windows Azure with minimal changes to your existing application.

For a list of specific templates that are supported for both C# and Visual Basic, see the following section: Supported Project Templates.

You must first enable your Web application for Windows Azure from Visual Studio. The following illustration shows the key steps to publish your existing Web application by adding a Windows Azure project to use for deployment. This process adds a Windows Azure project with the required Web role to your solution. Based on the type of Web project that you have, the project properties for assemblies are also updated if the service package requires additional assemblies for deployment.

Publish a Web application to Windows Azure
NoteNote

The Add Windows Azure Deployment Project command is displayed only for the Web project in your solution. For example, the command is not available for a Silverlight project in your solution.

To migrate and publish a Web application to Windows Azure from Visual Studio, you must follow these steps:

  1. Enable a Web application for deployment to Windows Azure (Steps 1 and 2 in the illustration above.)

  2. If you use a database in your application, you must change your connection strings to use a SQL Azure database: Use a SQL Azure database for your application

  3. If you write to a local file from your web application, you must set up local storage for your web role and write to this local storage: Manage local storage for each role instance.

  4. If you have specific assemblies that you have added to your Web application, you must set the properties to copy the assemblies so that they are also added to the service package: Include Files in the Service Package.

  5. Publish your Web application to Windows Azure (Steps 3 and 4 in the illustration above.)

NoteNote

When you create a service package or publish your application to Windows Azure, warnings or errors might occur. These warnings and errors can help you fix issues before you deploy to Windows Azure. For example, you might receive a warning about a missing assembly. For more information about how to treat any warnings as errors, see How to: Configure a Windows Azure Project with Visual Studio. For more information about how to troubleshoot these warnings or errors, see Troubleshooting Package Validation Warnings and Errors.

Caution noteCaution

If you build your application, run it locally using the compute emulator, or publish it to Windows Azure, you might see the following error in the Error List window: The specified path, file name, or both are too long. This error occurs because the length of the fully qualified Windows Azure project name is too long. The length of the project name, including the full path, cannot be more than 146 characters. For example, this is the full project name including file path for a Windows Azure project that is created for a Silverlight application: c:\users\<user name>\documents\visual studio 2010\Projects\SilverlightApplication4\SilverlightApplication4.Web.Azure.ccproj. You might have to move your solution to a different directory that has a shorter path to reduce the length of the fully qualified project name.

To enable a Web application for deployment to Windows Azure

  • To enable your Web application for deployment to Windows Azure, open the shortcut menu for a Web project in your solution and choose Add Windows Azure Deployment Project.

    The following actions occur:

    • A Windows Azure project called <name of the Web project>.Azure is added to the solution for your application.

    • A Web role for the Web project is added to this Windows Azure project.

    • The Copy Local property is set to true for any assemblies that are required for MVC 2, MVC 3 and Silverlight Business Applications. This adds these assemblies to the service package that is used for deployment.

      Important note Important

      If you have other assemblies or files that are required for this web application, you must manually set the properties for these files. For information about how to set these properties, see Include Files in the Service Package.

    Note Note

    If a web role for a specific web project already exists in a Windows Azure project in the solution, Add Windows Azure Deployment Project is not displayed on the shortcut menu for this web project.

If you have multiple Web projects in your Web application and you want to create Web roles for each Web project, you must perform the steps in this procedure for each Web project. This creates separate Windows Azure projects for each web role. Each Web project can be published separately. Alternatively, you can manually add another web role to an existing Windows Azure project in your web application. To do this, open the context menu for the Roles folder in your Windows Azure project and choose Add, Web Role Project in solution, select the project to add as a web role and choose the OK button.

If you have a connection string for your Web application that uses a SQL Server database, you must change this connection string to use a SQL Azure database instead.

Important note Important

You must have a subscription that enables you to use SQL Azure. If you access your subscription from the Windows Azure Management Portal, you can determine what services your subscription provides.

To use a SQL Azure database in your web role for your connection string

  1. To create a SQL Azure server in Windows Azure management console, follow the steps in the following article: Create a SQL Azure Server.

    Note Note

    When you set up the firewall rules for your SQL Azure server, you must select the Allow other Windows Azure services to access this server check box.

  2. To create a SQL Azure database to use for your connection string, follow the steps in the next section in the following article: Create a SQL Azure Database.

  3. To copy the ADO.NET connection string to use for your connection string, in the Windows Azure Management Portal perform the following steps:

    1. Choose the Database button. Then open the node for the subscription that you used to create your SQL Azure server.

    2. To display the available SQL Azure databases, open the SQL Azure server node.

    3. To view the properties for the database, choose the database. The Properties view is displayed.

      Note Note

      If the Properties view is not displayed, you might need to open the view by dragging the divider for the view to the left.

    4. To view the connection strings, choose the ellipsis button next to View.

      The Connection Strings dialog is displayed.

    5. To copy the ADO.NET connection string, highlight the text and press Ctrl+C.

    6. To close the dialog, choose the Close button.

  4. To replace the connection string in the web.config file to use this SQL Azure database, open the web.config file. Highlight the existing entry in the web.config file for the connection string entry and press Ctrl+V to replace the existing connection string with the ADO.NET connection string for the SQL Azure database.

  5. You must also add the parameter MultipleActiveResultSets=True to the connection string. The connection string should have the following format:

    connectionString=”Server=tcp:<database_server>.database.windows.net,1433;Database=<database_name>;User ID=<user_name>@<database_server>;Password=<myPassword>;Trusted_Connection=False;Encrypt=True;MultipleActiveResultSets=True"

  6. (Optional) An alternative method to changing the connection string directly in the web.config file is to add a section into one of the web.config transformation files, depending on the build configuration that you use to create your service package. Open either the Web.Debug.Config file or the Web.Release.Config file. Add the following section into this file:

    
    <connectionStrings>
       <add name="DefaultConnection" connectionString="Server=tcp:<database_server>.database.windows.net,1433;Database=<database_name>;User ID=<user_name>@<database_server>;Password=<myPassword>;Trusted_Connection=False;Encrypt=True;MultipleActiveResultSets=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>
    
    
  7. Save the file that you modified and republish your application.

To publish a Web application to Windows Azure

  1. To test the application in the local development environment using the Windows Azure compute emulator, open the shortcut menu for the Windows Azure project for the web role and choose Set as Startup Project. Then choose Debug, Start Debugging (Keyboard: F5).

    The Start the Windows Azure Debugging Environment dialog box is displayed. The application is started in the browser. For any specific details about how to start each type of Web application in the compute emulator, see the table in this section.

  2. To set up the services for your application to publish to Windows Azure, you must have a Windows Live ID and a Windows Azure subscription. Use the steps in the following topic to set up your services: Setting Up Services Required to Publish a Windows Azure Application from Visual Studio.

  3. To publish the Web application to Windows Azure, open the shortcut menu for the Web project and choose Publish to Windows Azure.

    The Publish Windows Azure Application dialog box is displayed. Visual Studio starts the deployment process. For more information about how to publish the application, see Publish a Windows Azure Application from Visual Studio.

    Note Note

    You can also publish the Web application from the Windows Azure project. To do this, open the shortcut menu for the Windows Azure project and choose Publish.

  4. To see the progress of the deployment, you can view the Windows Azure Activity Log window. This log is automatically displayed when the deployment process starts. You can expand the line item in the activity log to show detailed information, as shown in the following illustration:

    VST_AzureActivityLog
  5. (Optional) To cancel the deployment process, open the shortcut menu for the line item in the activity log and choose Cancel and remove. This stops the deployment process and deletes the deployment environment from Windows Azure.

    Note Note

    To remove this deployment environment after it has been deployed, you must use the Management Portal.

  6. (Optional) After your role instances have started, Visual Studio automatically shows the deployment environment in the Windows Azure Compute node in Server Explorer. From here you can view the status of the individual role instances. For more information about the Windows Azure Compute node in Server Explorer, see Viewing the State of an Azure Application using Server Explorer.

    The following illustration shows the role instances while they are still in the Initializing state:

    VST_DeployComputeNode
  7. To access your application after deployment, choose the arrow next to your deployment when a status of Completed is displayed in the Windows Azure Activity log. This displays the url for your Web application in Windows Azure. See the following table for the details about how to start a specific type of Web application from Windows Azure.

The following table lists the details about how to start specific Web applications from Windows Azure or to run or debug a web application locally using the Windows Azure Compute Emulator:

Web Application Type

Run/Debug Locally Using the Compute Emulator

Running in Windows Azure

ASP.NET Web Application

On the menu bar, choose Debug, Start Debugging (Keyboard: F5).

Choose the url hyperlink displayed in the Deployment tab for the Windows Azure Activity log to load the start page in the browser.

ASP.NET MVC 2 Web Application

On the menu bar, choose Debug, Start Debugging (Keyboard: F5).

Choose the url hyperlink displayed in the Deployment tab for the Windows Azure Activity log to load the start page in the browser.

ASP.NET MVC 3 Web Application

On the menu bar, choose Debug, Start Debugging (Keyboard: F5).

Choose the url hyperlink displayed in the Deployment tab for the Windows Azure Activity log to load the start page in the browser.

ASP.NET Empty Web Application

You must add an .aspx page in your application that you set as the start page for your web project. Then on the menu bar, choose Debug, Start Debugging (Keyboard: F5).

If you have a default .aspx page in your application, choose the url hyperlink displayed in the Deployment tab for the Windows Azure Activity log and this page is loaded in the browser. If you have a different .aspx page, you need to navigate to this specific page using the following format for your url:

<url for deployment>/<name of page>.aspx

Silverlight Application

On the menu bar, choose Debug, Start Debugging (Keyboard: F5).

You need to navigate to the specific page for your application using the following format for your url:<url for deployment>/<name of page>.aspx

Silverlight Business Application

On the menu bar, choose Debug, Start Debugging (Keyboard: F5).

You need to navigate to the specific page for your application using the following format for your url:<url for deployment>/<name of page>.aspx

Silverlight Navigation Application

On the menu bar, choose Debug, Start Debugging (Keyboard: F5).

You need to navigate to the specific page for your application using the following format for your url:<url for deployment>/<name of page>.aspx

WCF Service Application

You must set the .svc file as the start page for your WCF Service project. Then on the menu bar, choose Debug, Start Debugging (Keyboard: F5).

You need to navigate to the svc file for your application using the following format for your url:<url for deployment>/<name of service file>.svc

WCF Workflow Service Application

You must set the .svc file as the start page for your WCF Service project. Then on the menu bar, choose Debug, Start Debugging (Keyboard: F5).

You need to navigate to the svc file for your application using the following format for your url:<url for deployment>/<name of service file>.svc

ASP.NET Dynamic Entities

On the menu bar, choose Debug, Start Debugging (Keyboard: F5).

You must update the connection string.

You also need to navigate to the specific page for your application using the following format for your url:<url for deployment>/<name of page>.aspx

ASP.NET Dynamic Data Linq to SQL

On the menu bar, choose Debug, Start Debugging (Keyboard: F5).

You must follow the steps in this procedure: Use a SQL Azure database for your application.

You also need to navigate to the specific page for your application using the following format for your url:<url for deployment>/<name of page>.aspx

To Update a Connection String for ASP.NET Dynamic Entities

  1. To create a SQL Azure database that can be used for a ASP.NET Dynamic Entities Web application, you must follow the steps in this procedure: Use a SQL Azure database for your application.

  2. Add the tables and fields that you need for this database from the Windows Azure Platform Management Portal.

  3. The connection string for this type of application has the following format in the web.config file:

    <add name="tempdbEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=<server name>\SQLEXPRESS;initial catalog=<database name>;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    

    Update the connectionString value with the ADO.NET connection string for your SQL Azure database as follows:

    <add name="tempdbEntities" 
        connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Server=tcp:<SQL Azure server name>.database.windows.net,1433;Database=<database name>;User ID=<user name>;Password=<password>;Trusted_Connection=False;Encrypt=True;multipleactiveresultsets=True;App=EntityFramework&quot;" 
        providerName="System.Data.EntityClient" />
    
    
  4. To save the web.config file with the changes that you have made to the connection string, on the menu bar choose File, Save web.config.

To publish a Web application to Windows Azure, the application must use one of the project templates for C# or Visual Basic that is listed in the table below.

Project Template Group

Project Template

Web

ASP.NET Web Application

Web

ASP.NET MVC 2 Web Application

Web

ASP.NET MVC 3 Web Application

Web

ASP.NET Empty Web Application

Web

ASP.NET MVC 2 Empty Web Application

Web

ASP.NET Dynamic Data Entities Web Application

Web

ASP.NET Dynamic Data Linq to SQL Web Application

Silverlight

Silverlight Application

Silverlight

Silverlight Business Application

Silverlight

Silverlight Navigation Application

WCF

WCF Service Application

WCF

WCF Workflow Service Application

Workflow

WCF Workflow Service Application

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ