Get started with Azure and ASP.NET
A newer version of this tutorial is available. You can still follow this version if you want to use Visual Studio 2012, but it does not show all of the latest Azure SDK features.
This tutorial shows how to deploy an ASP.NET web application to an 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 an 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 Azure entirely for free.
This tutorial assumes that you have no prior experience using Azure. On completing this tutorial, you'll have a simple web application up and running in the cloud.
- How to enable your machine for Azure development by installing the Azure SDK.
- How to create a Visual Studio ASP.NET MVC 4 project and publish it to an Azure Web Site.
The following illustration shows the completed application:
- Set up the development environment
- Create a web site in Azure
- Create an ASP.NET MVC 4 application
- Deploy the application to Azure
- Next steps
Set up the development environment
To start, set up your development environment by installing the Azure SDK for .NET.
To install the SDK, click the link below. This tutorial requires Visual Studio 2012. If you don't have Visual Studio installed, Visual Studio Express for Web will be installed along with the SDK.
Note: Depending on how many of the SDK dependencies you already have on your machine, installing the SDK could take a long time, from several minutes to a half hour or more.
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.
When the installation is complete, you have everything necessary to start developing.
Create a web site
The next step is to create the Azure web site.
- In the 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 an 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 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 Azure.
Deploy the application to 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 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 an Azure web site will include your web site.
- In the Import Publish Profile dialog box, click Import from an Azure web site, and then click Add Azure subscription.
- In the Import Azure Subscriptions dialog box, click Download subscription file.
- In your browser window, save the .publishsettings file.
- In the Import Azure Subscriptions dialog box, click Browse and navigate to the .publishsettings file.
- Click Import.
The .publishsettings file contains your credentials (unencoded) that are used to administer your Azure subscriptions and services. The security best practice for this file is to store it temporarily outside your source directories (for example in the Libraries\Documents folder), and then delete it once the import has completed. A malicious user who gains access to the .publishsettings file can edit, create, and delete your Azure services.
In the Import Publish Profile dialog box, select Import from an 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. Click Next.
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 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.
In this tutorial, you've seen how to deploy a simple web application to an Azure Web Site. Other resources are available to show you how to manage, scale, and troubleshoot the site, how to add database, authentication, and authorization functionality, and how to decide if your application should run in an Azure Cloud Service instead of an Azure Web Site.
How to manage a web site
When you're done with the site, you can delete it, and at times you might want to take it offline temporarily or change site settings. You can do some of these functions right from Server Explorer in Visual Studio.
To delete your web site, you can use the Azure Management Portal. The following screen shot shows Stop, Restart, and Delete buttons in the Dashboard tab of the management portal.
You can change site settings on the Configure tab. For more information, see How to Manage Web Sites.
How to scale a web site
When your site is public and it starts to get more traffic, response times might slow down. To remedy that, you can easily add server resources in the Scale tab of the management portal.
For more information, see How to Scale a Web Site. (Adding server resources to scale a web site is not free.)
How to troubleshoot a web site
You might want to look at trace or log output for help with troubleshooting. Visual Studio provides built-in tooling to make it easy to view Azure logs as they are generated in real time.
For more information, see Troubleshooting Azure Web Sites in Visual Studio.
How to add database and authorization functionality
Most production web sites use a database and restrict some site functions to certain authorized users. For a tutorial that shows how to get started with database access, authentication, and authorization, see Deploy a Secure ASP.NET MVC app with Membership, OAuth, and SQL Database to an Azure Web Site.
How to decide if your application should run in a Cloud Service
In some scenarios you might want to run your application in an Azure Cloud Service instead of an Azure Web Site. For more information, see Azure Execution Models and Azure Web Sites, Cloud Services, and VMs: When to use which?. For a tutorial series 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.