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.
- 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:
To complete this tutorial, you need a Windows Azure account that has the Windows Azure Web Sites feature enabled.
- Set up the development environment
- Create a web site in Windows Azure
- Create an ASP.NET MVC 4 application
- Deploy the application to Windows Azure
- Next steps
Set up the development environment
To start, set up your development environment by installing the Windows Azure SDK for the .NET Framework.
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
When you are prompted to run or save the installation executable, click Run.
- In the Web Platform Installer window, click Install and proceed with the installation.
- 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 a web site
The next step is to create the Windows Azure web site.
- In the Windows Azure Management Portal, click Web Sites, and then click New.
- Click Quick Create.
- 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.
- 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.
- Click the Create Web Site arrow.
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.
Create 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
- Start Visual Studio 2012 or Visual Studio 2012 for Web Express.
- From the File menu, click New, and then click Project.
- In the New Project dialog box, expand C# and select Web under Installed Templates, and then select ASP.NET MVC 4 Web Application.
- Ensure that .NET Framework 4.5 is selected as the target framework.
- Name the application MyExample and click OK.
- In the New ASP.NET MVC 4 Project dialog box, select the Internet Application template and click OK.
Run the application locally
- Press CTRL+F5 to run the application. The application home page appears in the default browser.
This is all you need to do to create a simple application that you'll deploy to Windows Azure.
Deploy the application to Windows Azure
- In Visual Studio, right-click the project in Solution Explorer and select Publish from the context menu.
The Publish Web wizard opens.
- In the Profile tab of the Publish Web wizard, click Import.
The Import Publish Profile dialog box appears.
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.
b. In the Import Windows Azure Subscriptions dialog box, click Download subscription file.
c. In your browser window, save the .publishsettings file.
d. In the Import Windows Azure Subscriptions dialog box, click Browse and navigate to the .publishsettings file.
e. Click Import.
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.
- In the Connection tab, click Validate Connection to make sure that the settings are correct.
- When the connection has been validated, a green check mark is shown next to the Validate Connection button. Click Next.
- 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.
- In the Preview tab, click Start Preview.
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.
- Click Publish.
Visual Studio begins the process of copying the files to the Windows Azure server.
- The Output window shows what deployment actions were taken and reports successful completion of the deployment.
- 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.
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.