This tutorial shows how to deploy an ASP.NET web application to an Azure Web Site by using Visual Studio 2010 or Visual studio 2012. This is the most useful and highly used by developers when they doing development of Windows Azure.
I believe you already has a Azure account as this is the prerequisite for this tutorial. If you don't have one please check here how to get one.
If you are following the previous tutorials then you must have development environment setup either for visual studio 2013 or 2012/2010. If not, setup the development environment by installing Azure SDK and other related tools - refer previous tutorial here to get more details about how to setup dev environment for Azure development.
There will be three main steps in this tutorial.
4. 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.
I believe you already has a Azure account as this is the prerequisite for this tutorial. If you don't have one please check here how to get one.
If you are following the previous tutorials then you must have development environment setup either for visual studio 2013 or 2012/2010. If not, setup the development environment by installing Azure SDK and other related tools - refer previous tutorial here to get more details about how to setup dev environment for Azure development.
There will be three main steps in this tutorial.
- Create a website in Windows Azure portal.
- Create a Asp.net MVC application using Visual Studio.
- Publish the application to Windows Azure.
Let's see these steps in detail.
Create website in Windows Azure portal
If you have already created a website in Windows Azure portal and knows how to do it, you can skip this section, otherwise follow along.
1. Login to the Windows Azure management portal , click Web Sites and then click New at the bottom side.
2. A fly out menu will appear with website selected. It will present three option for creating an Azure Web Site : Quick Create, Custom Create and From Gallery. Click on quick create.
3. Choose a unique name for your site. If your site name is unique, there will be little green check mark appears as shown in the figure. If it's not unique, an alert will appear and you have to choose unique name.This setting specifies which data center your web site will run in. For now, choose the region closet to you.
4. 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 a Asp.net MVC application
Now our website has been created, but there is no content in it yet. In this step we are going to create a web application that we gonna publish to Azure.
1. Open Visual Studio 2010/2012.
2. Go to File menu and then New -> Project. In the new project dialog box, expand Visual C# and select Web under Installed Template, and then select ASP.NET MVC 4 Web Application. Ensure that .NET Framework 4.0 or 4.5 is selected as the target framework. Name the application "testazure4" (I have given the same name as my website), and click OK.
3. In the New ASP.NET MVC 4 Project dialog box, select the Internet Application template and click OK.
4. Visual Studio use a default template for the ASP.NET MVC project. So the application that you have just created is working without doing any changes. Since the main purpose of this tutorial is to show how to deploy the application right from Visual Studio, the default project with no changes is sufficient. However you can go ahead and change the content if you want and if you obviously know the MVC. Press CTRL + F5 to run your application. The application home page appears in the browser. The same page we expect to appear when we deploy our application to Windows Azure.
Publish the application to Windows Azure
Now the most important part of this tutorial, we are going to publish this website to Windows Azure.
In order to publish through Visual Studio, you need a publish setting file (also known as subscription file), which can be downloaded from Windows Azure Management Portal. The publish settings file is just an XML file with your subscription details (id, name, url) as well as a management certificate for authenticating management API requests. Without this file you need to create certificate in your local certificate store and export the same to Azure portal, and then you use this certificate in Visual Studio and associate your subscription ID with each operation. With publish setting file, you have to just download this file from portal and import in Visual Studio.
To can download this file from the link https://windows.azure.com/download/publishprofile.aspx .
You may need to login with your subscription account. Once downloaded save it in your local drive.
The publish seeting file name will be in this format:
<Subscription_Name>-<Download_Date>-credentials.publishsettings
Note : 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.
1. Go back to the Visual Studio right-click the project in Solution Explorer and select Publish from the context menu.
2. This will open Publish Web Wizard. In the profile tab of Publish Web Wizard, click Import.
3. The Import Publish Profile dialog box appears. In the Import Publish Profile dialog box, click Import from an Azure web site, and then click Add Azure subscription.
4. It will open Import Azure Subscriptions dialog box. We have already downloaded the subscription file. Browse to the path where you have downloaded the file. Select the file and click on Import button.
5. Once you add your subscription,drop-down list under Import from an Azure web site will include all your web sites. Select your website from the drop down list and click OK.
6. In the Connection tab, click Validate Connection to make sure that the settings are correct.
7. When the connection has been validated, a green check mark is shown next to the Validate Connection button. Click Next.
8. 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.
9. In the Preview tab, click Start Preview.
10. 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.
11. Click Publish. Visual Studio begins the process of copying the files to the Azure server.
12. 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 as evident from the URL.
So, that's about it, publishing website from Visual Studio 2010/2012. These are the same steps you need to perform to publish any website from Visual Studio, only import part you don't need to every time. In the next tutorial we learn how to publish using Visual Studio 2013.
No comments:
Post a Comment