Get started with Windows Azure and ASP.NET
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 2013 or Visual Studio 2013 for Web Express. (If you prefer to use Visual Studio 2012, see the previous version of this tutorial.)
You can open a Windows Azure account for free, and if you don't already have Visual Studio 2013, the SDK automatically installs Visual Studio 2013 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 5 project and publish it to a Windows Azure Web Site.
The following illustration shows the completed application:
- Set up the development environment
- Create an ASP.NET MVC 5 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 .NET.
- To install the SDK, click the link below. This tutorial requires Visual Studio 2013. If you don't have Visual Studio installed, Visual Studio Express for Web will be installed along with the SDK.
- Windows Azure SDK for Visual Studio 2013
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 an ASP.NET MVC 5 application
Your first step is to create a Visual Studio web application project that you'll publish to Windows Azure.
Create the project
Open Visual Studio 2013 or Visual Studio 2013 Express for Web.
From the File menu, click New Project.
In the New Project dialog box, expand C# and select Web under Installed Templates, and then select ASP.NET Web Application.
Make sure that .NET Framework 4.5 is selected as the target framework.
Name the application MyExample and click OK.
In the New ASP.NET Project dialog box, select the MVC template, and then click Change Authentication.
In the Change Authentication dialog box, click No Authentication, and then click OK.
The sample application you're creating won't have features that require users to log in. For information about how to implement authentication and authorization features, see the Next Steps section at the end of this tutorial.
In the New ASP.NET Project dialog box, click OK.
Run the application locally
Press CTRL+F5 to run the application.
The application home page appears in the default browser.
http://localhost URL shows that it's running on your local computer. By default it's running in IIS Express, which is a lightweight version of IIS designed for use during web application development.
This is all you need to do to create a simple application that you can deploy to Windows Azure.
Deploy the application to Windows Azure
Close the browser.
In Visual Studio Solution Explorer, right-click the project, and then 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.
Use one of the following methods to enable Visual Studio to connect to your Windows Azure account.
Click Sign In, and then enter the credentials for your Windows Azure account.
This method is quicker and easier, but if you use this method you won't be able to see Windows Azure SQL Database or Mobile Services in the Server Explorer window.
Click Manage subscriptions in order to install a management certificate that enables access to your account.
In the Manage Windows Azure Subscriptions dialog box, click the Certificates tab, and then click Import. Follow the directions to download and import a subscription file (also called a .publishsettings file) for your Windows Azure account.
Download the subscription file to a folder outside your source code directories (for example, in the Downloads folder), and then delete it once the import has completed. A malicious user who gains access to the subscription file can edit, create, and delete your Windows Azure services.
For more information, see Manage Accounts, Subscriptions, and Administrative Roles.
In the Import Publish Settings dialog box, select the Import from a Windows Azure Web Site radio button, and then click New.
In the Create a site on Windows Azure dialog box, enter a string in the Site name 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. If someone else has already used the URL you entered, you'll see a red exclamation mark to the right instead of a green check mark, and you'll need to enter a different value.
In the Location drop-down list, choose the location that is closest to you.
This setting specifies which data center your web site will run in.
Leave the database fields unchanged.
For this tutorial you aren't using a database. The Next Steps section at the end of the tutorial links to a tutorial that shows you how to use a database.
In a few seconds the web site is created. When you return to the Import Publish Settings dialog box, the new site is selected in the drop-down list.
In the Connection tab of the Publish Web wizard, 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.
In the Settings tab, click Next.
You can accept the default settings on this tab. You're 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.
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.
In this tutorial, you've seen how to deploy a simple web application to a Windows 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 a Windows Azure Cloud Service instead of a Windows Azure Web Site.
How to manage a web site
The Windows Azure Management Portal is a web interface that you can use to manage and monitor all of your Windows Azure services.
You can make new web sites, cloud services, virtual machines, databases, and more. You can create open source applications from the gallery. And you can manage services that you've created. For example, the following screen shot shows Stop, Restart, and Delete buttons for a Windows Azure Web Site in the Dashboard tab of the management portal. The Dashboard also shows performance statistics such as CPU time used, number of requests, data in and out, and any errors that may have occurred.
You can change many other site settings on the Configure tab. For more information, see How to Manage Web Sites.
You can also do some web site management functions right from Server Explorer in Visual Studio. For information about what you can do in Server Explorer, see Troubleshooting Windows Azure Web Sites in Visual Studio.
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 Windows Azure logs as they are generated in real time. You can also run in debug mode remotely in Windows Azure. For more information, see Troubleshooting Windows 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 a Windows 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 a Windows Azure Cloud Service instead of a Windows Azure Web Site. For more information, see Windows Azure Execution Models and Windows 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.