Exportera (0) Skriv ut
Visa allt
EN
Det här innehållet finns inte tillgängligt på ditt språk men här finns den engelska versionen,

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

Updated: October 14, 2013

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 Convert, Convert to Windows Azure Cloud Service 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 Windows Azure SQL Database: Use a Windows Azure SQL 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 Azure Project with Visual Studio. For more information about how to troubleshoot these warnings or errors, see Troubleshooting Package Validation Warnings and Errors.

CautionCaution
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.

Enable a Web Application for Deployment to Windows Azure

To enable a web application for deployment to Windows Azure

  1. 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, MVC 4, and Silverlight Business Applications. This adds these assemblies to the service package that is used for deployment.

      ImportantImportant
      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.

    noteNote
    If a web role for a specific web project already exists in a Windows Azure project in the solution, Convert, Convert to Windows Azure Cloud Service 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 shortcut menu for the Roles folder in your Windows Azure project, choose Add, then Web Role Project in solution, choose the project to add as a web role, and then choose the OK button.

Use a Windows Azure SQL Database for Your Application

If you have a connection string for your web application that uses a SQL Server database that's on the premises, you must change this connection string to use an instance of SQL Database that Windows Azure hosts instead.

ImportantImportant
Your subscription must enable you to use SQL Database. If you access your subscription from the Windows Azure Management Portal, you can determine what services your subscription provides.

The following instructions apply to the released Management Portal. If you are using the Preview Management Portal, skip to the next procedure.

To use a SQL Database instance in your web role for your connection string

  1. To create an instance of SQL Database in the management console for Windows Azure, follow the steps in the following article: Create a SQL Database Server.

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

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

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

    1. Choose the Database button, and then open the node for the subscription that you used to create your instance of SQL Database.

    2. To display the available instances of SQL Database, choose the SQL Databases node.

    3. To display the properties for the database, choose the database. The Properties view appears.

      noteNote
      If the Properties view doesn't appear, you might need to open it by using the divider.

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

      The Connection Strings dialog box appears.

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

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

  4. To replace the connection string in the web.config file to use this instance of SQL Database, open the web.config file, highlight the existing connection string entry, and then choose the Ctrl+V keys.

    The ADO.NET connection string for the instance of SQL Database replaces the existing connection string.

  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 use an instance of SQL Database by using the Management Portal

  1. In the Management Portal, choose the SQL Databases node.

    • If the instance of SQL Database that you want to use appears, choose to open it.

    • If you haven't created any instances, choose the appropriate link, and then create an instance.

  2. After you open or create a database instance, choose the Connection Strings link.

  3. At the bottom of the page, choose the link to configure firewall settings, and accept the default values or configure the values that you need.

  4. Copy the ADO.NET connection string, paste it into your web.config file over the old connection string for the on-premises database, and be sure to add "MultipleActiveResultSets=True".

Publish a Web Application to Windows Azure

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 Microsoft account and a Windows Azure subscription. Use the steps in the following topic to set up your services: Setting Up Services Required to Publish a Cloud Service 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.

    noteNote
    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.

    noteNote
    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 a Cloud Service 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: Choose the F5 key.).

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: Choose the F5 key.).

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: Choose the F5 key.).

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 4 Web Application

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

To load the start page in the browser, choose the URL link that appears on the Deployment tab for the Windows Azure Activity log.

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: Choose the F5 key.).

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: Choose the F5 key.).

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: Choose the F5 key.).

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: Choose the F5 key.).

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: Choose the F5 key).

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: Choose the F5 key.).

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: Choose the F5 key.).

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: Choose the F5 key).

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

Update a Connection String for ASP.NET Dynamic Entities

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.

Supported Project Templates

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 MVC4 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

See Also

Gruppinnehåll

Lägg till
Visa:
© 2014 Microsoft