Free trial *Internet Service Required

Deploying an ASP.NET Web Application to a Windows Azure Web Site

This tutorial shows how to deploy an ASP.NET web application to a Windows Azure Web Site by using the Publish Web wizard in Visual Studio 2012 or Visual Studio 2012 for Web Express. If you prefer, you can follow the tutorial steps by using Visual Studio 2010 or Visual Web Developer Express 2010.

You can open a Windows Azure account for free, and if you don't already have Visual Studio 2012, the SDK automatically installs Visual Studio 2012 for Web Express. So you can start developing for Windows Azure entirely for free.

This tutorial assumes that you have no prior experience using Windows Azure. On completing this tutorial, you'll have a simple web application up and running in the cloud.

You'll learn:

  • How to enable your machine for Windows Azure development by installing the Windows Azure SDK.
  • How to create a Visual Studio ASP.NET MVC 4 project and publish it to a Windows Azure Web Site.

The following illustration shows the completed application:

Web site example

Note

To complete this tutorial, you need a Windows Azure account that has the Windows Azure Web Sites feature enabled.

Tutorial segments

  1. Set up the development environment
  2. Create a web site in Windows Azure
  3. Create an ASP.NET MVC 4 application
  4. Deploy the application to Windows Azure
  5. Next steps

Set up environmentSet up the development environment

To start, set up your development environment by installing the Windows Azure SDK for the .NET Framework.

  1. To install the Windows Azure SDK for .NET, click the link that corresponds to the version of Visual Studio you are using. If you don't have Visual Studio installed yet, use the Visual Studio 2012 link.
    Windows Azure SDK for Visual Studio 2012
    Windows Azure SDK for Visual Studio 2010

  2. When you are prompted to run or save the installation executable, click Run.

  3. In the Web Platform Installer window, click Install and proceed with the installation.
    Web Platform Installer - Windows Azure SDK for .NET
  4. If you are using Visual Studio 2010 or Visual Web Developer 2010 Express, install MVC 4.

When the installation is complete, you have everything necessary to start developing.

Create siteCreate a web site

The next step is to create the Windows Azure web site.

  1. In the Windows Azure Management Portal, click Web Sites, and then click New.
    New web site
  2. Click Quick Create.
    Quick create
  3. In the Create Web Site step of the wizard, enter a string in the URL box to use as the unique URL for your application.
    The complete URL will consist of what you enter here plus the suffix that you see next to the text box. The illustration shows example1, but if someone has already taken that string for a URL, you need to enter a different value.
  4. In the Region drop-down list, choose the region that is closest to you.
    This setting specifies which data center your web site will run in.
  5. Click the Create Web Site arrow.
    Create a new web site
    The Management Portal returns to the Web Sites page, and the Status column shows that the site is being created. After a while (typically less than a minute), the Status column shows that the site was successfully created. In the navigation bar at the left, the number of sites you have in your account appears next to the Web Sites icon.
    Web Sites page of Management Portal, web site created

Create the appCreate an ASP.NET MVC 4 application

You have created a Windows Azure Web Site, but there is no content in it yet. Your next step is to create the Visual Studio web application project that you'll publish to Windows Azure.

Create the project

  1. Start Visual Studio 2012 or Visual Studio 2012 for Web Express.
  2. From the File menu, click New, and then click Project.
    New Project in File menu
  3. In the New Project dialog box, expand C# and select Web under Installed Templates, and then select ASP.NET MVC 4 Web Application.
  4. Ensure that .NET Framework 4.5 is selected as the target framework.
  5. Name the application MyExample and click OK.
    New Project dialog box
  6. In the New ASP.NET MVC 4 Project dialog box, select the Internet Application template and click OK.
    New ASP.NET MVC 4 Project dialog box

Run the application locally

  1. Press CTRL+F5 to run the application. The application home page appears in the default browser.
    Web site running locally

This is all you need to do to create a simple application that you'll deploy to Windows Azure.

Deploy the appDeploy the application to Windows Azure

  1. In Visual Studio, right-click the project in Solution Explorer and select Publish from the context menu.
    Publish in project context menu
    The Publish Web wizard opens.
  2. In the Profile tab of the Publish Web wizard, click Import.
    Import publish settings The Import Publish Profile dialog box appears.
  3. If you have not previously added your Windows Azure subscription in Visual Studio, perform the following steps. In these steps you add your subscription so that the drop-down list under Import from a Windows Azure web site will include your web site.

    a. In the Import Publish Profile dialog box, click Import from a Windows Azure web site, and then click Add Windows Azure subscription.

    add Windows Azure subscription

    b. In the Import Windows Azure Subscriptions dialog box, click Download subscription file.

    download subscription file

    c. In your browser window, save the .publishsettings file.

    download .publishsettings file

    d. In the Import Windows Azure Subscriptions dialog box, click Browse and navigate to the .publishsettings file.

    download sub

    e. Click Import.

    import

  4. In the Import Publish Profile dialog box, select Import from a Windows Azure web site, select your web site from the drop-down list, and then click OK.
    Import Publish Profile

  5. In the Connection tab, click Validate Connection to make sure that the settings are correct.
    Validate connection
  6. When the connection has been validated, a green check mark is shown next to the Validate Connection button. Click Next.
    Successfully validated connection
  7. In the Settings tab, uncheck Use this connection string at runtime option, since this application is not using a database. You can accept the default settings for the remaining items on this page. You are deploying a Release build configuration and you don't need to delete files at the destination server, precompile the application, or exclude files in the App_Data folder.
    Click Next.
    Settings tab
  8. In the Preview tab, click Start Preview.
    StartPreview button in the Preview tab
    The tab displays a list of the files that will be copied to the server. Displaying the preview isn't required to publish the application but is a useful function to be aware of. In this case, you don't need to do anything with the list of files that is displayed.
    StartPreview file output
  9. Click Publish.
    Visual Studio begins the process of copying the files to the Windows Azure server.
  10. The Output window shows what deployment actions were taken and reports successful completion of the deployment.
    Output window reporting successful deployment
  11. Upon successful deployment, the default browser automatically opens to the URL of the deployed web site.
    The application you created is now running in the cloud.
    Web site running in Windows Azure

Next stepsNext steps

You've seen how to deploy a web application to a Windows Azure Web Site. When you are finished with your deployed web site, you can delete it in the Windows Azure management portal. In the Web Sites tab, click the name of the site you want to delete and click Delete.

For information about how to deploy a web application that includes a SQL Server database, see Deploy a Secure ASP.NET MVC app with Membership, OAuth, and SQL Database to a Windows Azure Web Site.

To learn more about how to configure, manage, and scale Windows Azure Web Sites, see the how-to topics on the Web Sites management page.

You can deploy a web application to a Windows Azure Cloud Service instead of a Windows Azure Web Site. For more information, see Windows Azure Execution Models. For a tutorial that shows how to create a multi-tier ASP.NET web application and deploy it to a Cloud Service, see .NET Multi-Tier Application Using Storage Tables, Queues, and Blobs - 1 of 5.

Rss Newsletter