Friday, May 23, 2014

Part 11 : Windows Azure Web Sites - Deployment using Visual Studio 2010/2012

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.

  1. Create a website in Windows Azure portal.
  2. Create a Asp.net MVC application using Visual Studio.
  3. 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.

Wednesday, May 7, 2014

Part 10 : Windows Azure Web Sites - Deployment using FTP

The File Transfer Protocol (FTP) is a standard network protocol used to transfer computer files from one host to another host over a TCP-based network, such as the Internet.

FTP is built on a client-server architecture and uses separate control and data connections between the client and the server.[1] FTP users may authenticate themselves using a clear-text sign-in protocol, normally in the form of a username and password, but can connect anonymously if the server is configured to allow it. For secure transmission that protects the username and password, and encrypts the content, FTP is often secured with SSL/TLS (FTPS). SSH File Transfer Protocol (SFTP) is sometimes also used instead, but is technologically different.

FTP is the traditional method of deploying your content to web server and many web developers are familiar with it.
In order to use FTP in Azure, you need to configure it. Your windows azure credentials will not work as FTP (or any other third party provider like Git) do not recognize Microsoft accounts.

You can configure the FTP credentials right from the Windows Azure portal by following these steps.

1. Login to Windows Azure portal using your credentials.
2. Select any website that you have already created.
 






3. After clicking on the site go to the dashboard of the site. Once you are in dashboard, click on "Set up deployment credentials" link on the right hand side as shown in the figure below.


4. On clicking of this link will open a pop up window that allows you to set credentials as shown in the figure      below.


5. Enter username and password and click on the right button. Once done you will get a notification     that Your deployment credentials were set successfully. This user name and password can be used to     deploy to any web site in all subscriptions associated with the account you use to log into the Windows     Azure portal. You do not need to set credentials for every web site that you create. Once you have set the credentials the link changes to "Reset your deployment credentials". As the name suggests, you can reset your credentials from here in case you forget or just simply change it.


To deploy using FTP, you need FTP server details , your username and password.
To get the server details of the web site your are uploading contents to, go to the dashboard of the website and you can see the FTP server details on the right hand side of the page as shown in the figure below.

























If you pay attention closely to the FTP host name, then you find out that FTP host name is same for all the websites. But it's the "Deployment/FTP User " that is different for each website.
For example in my account for the test-learnwindowsazure website I have  "Deployment/FTP User " as 
test-learnwindowsazure\vjoshi
but for the website test1-learnwindowsazure it is
test1-learnwindowsazure\vjoshi

Now the following steps will explain how to deploy a simple html page to azure website.
1. Create a new file index.html and type the following contents to it. (or create any html file or use existing 
         one).
         <html>
             <body>
                   <h1> My first Azure website </h1>
             </body>
          </html>
2. You can use any FTP client to connect to Azure FTP location. Here I have used FileZilla.
    Give host, username and password to connect. For the user, give full user name. For the local site go to
    the directory where you have stored index.html, for me it's C:\Colud\Website. For the remote site go
    to /site/wwwroot.
 

3. Currently wwwroot has only one file "hostingstart.html". Drag index.html from local to remote and your file     will be uploaded to remote.

4. Go back to website listing in Windows Azure portal and click on the URL of the website for which you 
    have uploaded the content.
    
   Clicking on this URL will open the website and since index.html is the default page for website, it will show    the content of it.
 
 
These are just the simple steps that you follow to upload your content to Azure websites via FTP.
The same steps you need to follow whether you are uploading one file or hundreds of file.

Tuesday, May 6, 2014

Part 9 : Windows Azure Web Sites - Deployment Options

In the last tutorial we have created one web site in Windows Azure, but so for our web site is empty. We need to add some content to it. But before adding content let's see what all options are out there to deploy your source code to Windows Azure Web Sites. With Windows Azure Website, deployment of new and existing web sites is very quick and flexible.
  1. Upload your content through FTP.
  2. Publish from Web Matrix
    WebMatrix is a free, lightweight, cloud-connected web development tool. WebMatrix 3 brings you easy access to your Windows Azure websites. You can access your remote sites as seamlessly as local sites. 
  3. Publish from Visual Studio
    You can publish your Azure application to Azure directly from Visual Studio. Microsoft made it very easy so that any developer can deploy his website easily on the cloud. 
  4. Dropbox
    Dropbox is a free service that lets you bring your photos, docs, and videos anywhere and share them easily. You can simply put the source code into the local dropbox folder and it will quickly synchronize and deployed to Windows Azure.
  5. Local Git Repository
    You can directly publish source code from your local Git Repository to Windows Azure and your site will go  live quickly and automatically.
  6. GitHub
    GitHub is a web-based hosting service for software development projects that use the Git revision control system. From Windows Azure web site you can connect to any branch of GitHub project associated with your account.
  7. Bitbucket
    Bitbucket is a web-based hosting service for projects that use either the Mercurial or Git revision control systems. Bitbucket includes an issue tracker, a wiki, and integration with popular  services such as Basecamp, Flowdock, and Twitter.
  8. CodePlex
    CodePlex is an open source project hosting website from Microsoft. It allows shared development of open source software. To integrate with Windows Azure , your project must use Git ot Mercurial as the source control provider.

As you can see there are many deployment options are available and each of them has it's own advantages.
Also it depends on your needs which one you choose to choose.

We will be covering all of the above options in details in coming chapters, but at least for now our main concentration will be on publishing from Visual Studio. Visual Studio and Web matrix gives you option to publish the content directly from the tool. This way of deployment isn't good when you are working with other team members. It's difficult to track changes and there is no way to rollback to previous version. But it's best while you are learning and playing with Windows Azure.  

Wednesday, April 9, 2014

Part 8 : Windows Azure Web Sites - Basic

Windows Azure Web Sites (WAWS) is a PaaS based web-hosting platform that supports multiple technologies, and programming languages (.NET, node.js, php, Python). Users with Windows Azure subscriptions can create Web Sites, and deploy content and code into the web sites. If you have done the traditional website deployment in the past, you know well that how difficult is to provision your own web server. Well Windows Azure comes to rescue. You don't have to deal with hardware and operating systems anymore with Windows Azure. You have to just concentrate on building your website and once it's ready, you have to push the code to Windows Azure web site using one of the deployment methods available that we will discuss shortly.

Windows Azure Web Sites is implemented as websites that are dynamically created on-demand on servers running Windows Server 2012 and IIS 8.0. When a client posts a request to a web site, Windows Azure Web Sites dynamically provisions the site on one of the Azure virtual machines pointing it at content stored in Azure Storage containers (just like in IIS you need to point to directory where content is stored).

Now Windows Azure offers several ways to host your web applications, such as Windows Azure Web Sites, Cloud Services, and Virtual Machines. What are the reasons you prefer Windows Azure Web Sites over Cloud service and Virtual machines?

Web Sites are easier to set up, manage, and monitor, but you have fewer configuration options. The key point is that when you do not have a compelling reason to place your web front-end on Cloud Services or Virtual Machines, use Windows Azure Web Sites.
Also Web Sites are best for running web applications that are relatively isolated (that do not require elevated security, remote desktop, network isolation etc.) and do not require installation of any applications (MSI, COM Object etc).  In Web Sites, you cannot alter the VM instance at all.

The great thing about Windows Azure Web Sites is that you can start using it for free and then add more capabilities when you need them.  For example, each free web site comes with a domain provided by Windows Azure (your_company.azurewebsites.net). When you’re ready to start using your own domain, you can add this. There are many other services and scaling options that allow the site to evolve with increased user demand.

The Azure Platform is supported by growing network of Microsoft-managed data-centers around the world that are capable of hosting WAWS and other Azure services. You can deploy your application to the data-center that is closest to your user base.

Azure Web Sites has the following advantages :
  • Near-instant deployment with deployment history / rollbacks
  • github, local git, ftp, CodePlex, DropBox, BitBucket deployment support
  • Much faster site provisioning and scaling
  • Use the Application Gallery to quickly setup popular web applications, such as WordPress.
  • Simple and fast to scale from free tier to shared tier to dedicated tier
  • Friendlier in-built  monitoring and diagnostics
  • Multiple websites (deployed separately) on a single farm out of the box

Enough of the theory, now let's do some practical and create our first Windows Azure Web Site (from now on we will refer as WAWS).

At this point I assume that you have already taken the Windows Azure subscription either paid one or trial.
Follow these steps to quickly create a new WAWS :

1. Login to the Windows Azure Management Portal. (http://manage.windowsazure.com/)

2. Click the Create New icon in the context menu at the bottom left of the Management Portal.

3. A fly-out menu will appear. Go to COMPUTE -> WEB SITE. It will present three option for creating an Azure Web Site :  Quick Create, Custom Create and From Gallery.
  









4. Click on "QUICK CREATE", which opens a panel to name your site. If this is the first site being created in a specific data center then it would be scaled to FREE mode by default. Also the name of the site will  be <name>.azurewebsites.net . In order to give custom domain name, you will have to scale it to either SHARED or STANDARD. We will look into that later.

5. 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. Choose the region closet to you (we will go into the details later) and click the check mark next to Create Web Site on the bottom right corner of the page.

















6. When the web site has been created, you will see the text Creating web site <web site name> succeeded.   You can browse to the web site by clicking Browse at the bottom of the portal page.
7. If you click on WEB SITES link on the navigation panel on the left you can see your newly created site listed. Since there is no content so far for our newly created site, you can see the default page when you browse the site.
 
    












Congratulations on creating your first website. This website is currently blank and we have to add content to it. We will add content to this website as well explore WAWS in depth in the subsequent tutorials.

Friday, March 7, 2014

Part 7 : Setting up Development Environment

In order to start development on Windows Azure projects, you need to have SDK and tools. Now since Windows Azure supports multiple languages, you need to install the relevant SDK. This tutorial is all about setting up the .net devleopment environment, but you can install the appropriate SDK relevant to your development environment.

Prerequisites

  • Azure Account – Get a Free Windows Azure
  • .NET Framework 4.0 or above.
  • Operating System : windows vista sp1 or higher, windows 7, windows server 2008 or higher
  • IIS 7.x/8 (with ASP.NET and WCF HTTP Activation) , check that you have relevant components installed under IIS. To check that go to Control Panel and then select Programs And Features, and then click the Turn Windows Features On Or Off . Under Internet Information Services, expand World Wide Web Services and make sure that the following items are selected ASP.NET, CGI, WCF HTTP Activation, and Static Content.

  • Microsoft Web Platform Installer (Not compulsory but nice to have)
    The Microsoft Web Platform Installer (Web PI) is a free tool that makes getting the latest components of the Microsoft Web Platform, including Internet Information Services (IIS), SQL Server Express, .NET Framework and Visual Web Developer easy. Web PI is used to download all the tools for Windows Azure. Get more details at http://www.microsoft.com/web/downloads/platform.aspx
  • Last but most important is good internet connection. After all you will going to deploy your application in cloud.

Download and Install Windows Azure SDK

The windows Azure SDK for  .NET enables developers to build, debug, deploy and manage scalable applications and services on Windows Azure. The SDK includes client libraries for Windows Azure Storage, Service Bus, Caching, and other services. Full Visual Studio integration with authoring, debugging, and deployment support for Windows Azure Web Sites and Cloud Services is included. Deployment Storage and Development Fabric emulators are also included, as well as nodes in Server Explorer for managing Windows Azure services.

You can get the latest SDK for any development platform from here :
http://www.windowsazure.com/en-us/downloads/

Note that latest SDK version 2.2 for .net is available only for Visual Studio versions 2012 and 2013.
If you want to install SDK for visual studio 2010, you need to go at this location to install previous SDK :
http://www.windowsazure.com/en-us/downloads/archive-net-downloads/



The above links are automated one-click installs that provide you everything you need to get started.

However there are times when you need to install components manually. Windows Azure provides advanced manual installation of the SDK for .NET, which include SDKs, basic tools, and extended tools for VS 2012 and VS 2013.  Check link below for manual installation :
http://www.microsoft.com/en-us/download/details.aspx?id=40893


Instead of manually downloading the files below, it is recommended you use the automated one-click install provided by the Web Platform Installer.


Once everything is setup, I recommend to to download Platform Training Kit, which has tutorials and labs to get you started.




Monday, February 24, 2014

Part 6 : Windows Azure Portal Tour

I assume that you now have Windows Azure subscription either free or paid one. In this tutorial I am going to walk you through using the management portal for Windows Azure.

To reach the management portal you need go to  https://manage.windowsazure.com/ and logging in with your susbcription userid and password.  You can manage all your Windows Azure platform resources from a single location and that is Windows Azure Management portal. Windows Azure Management Portal is a slick HTML5 website with much better accessibility from mobile devices.

Windows Azure Management portal evolves over time and  Azure development team continues to make improvements to various aspects of the management portal. So don't surprise to see new things in Management portal.

Once you login to the portal, you'll be taken to the dashboard, where you can see "all items" grid that list out all items on your account from all the feature areas of your Windows Azure platform resources (this includes cloud services, VM's, mobile services, SQL Databases, Storage, service bus etc.). The information that is being shown for each item are name, type, status, subscription detail and location. As you see this area provides a nice snapshot of all your items with thier status.

Figure 1

You can also sort the grid's contents by clicking the column header. Also you can filter items in the grid by clicking the magnifying class in the rightmost column header and typing in the characters you want to search for. The search will match values in the Name, Type, Status, or Location columns that contain the entered text.  Now if you click on the name of any of the items listed in the grid, it will take you to the detailed dashboard for that particular item. 


As you can see in the figure 1 , there is a navigation pane on the left that lists out all the features. Clicking on any feature on the left navigation, for example Web Sites, presents the list of items filtered to that feature as shown in figure 2. More tabs will be added on the left navigation as new features are released. Please note that you may be required to enable the new features from your account settings before they can be displayed here. 
Figure 2

Notice that when you select any item in a particular category, example any website in WEB SITES category, left navigation panel collapse to show only icons to give more space and also to show the selected item. In addition, selecting that item will take you to the dashboard to manage that item as shown in figure 3.
Figure 3

There is a command bar at the bottom which is context sensitive that means that it will show options based on the items you selected on grid or left navigation pane. For example if you select any item from WEB SITES, the command bar will show items like Browse, Stop, Restart etc. relevant to web sites. If you select cloud service the command items will be different. We will cover all the options later as we will look in detail each category.







Notice that there is +NEW button at the left of the command bar. Click on it will open a fly-out window will open that present options to create new items. By default it will select the item to be created of the same category that you have selected on left navigation pane. For example if you have selected web site from left navigation pane, when you click on +NEW button, it will open fly-out window with web site selected.




Windows Azure management portal keeps you updated about the status of services in real time. If you see the list under any category, there is a status column that shows the real time status of that item. 

There is a green status icon on the right hand side of the command bar at the bottom. As you are doing operations on Windows Azure Management portal, this icon tells you the real time status of the operation that you have started.  Clicking on it will open a fly-out window that shows the detail status of the operation you have started. Once operation has been done, you can click on the OK button to dismiss that notification.
















Part 5 : Windows Azure Subscription

In order to use Windows Azure, we need to have a subscription for Windows Azure.
The http://www.windowsazure.com web-site provides everything you need to get started with Windows Azure – including overview content, developer tutorials and documentation, account management, and more.

In order to deploy applications to Windows Azure, you need an account. This article describes various options to get a free trial account (and paid one).

Option 1 : Windows Azure Trial Account
Sign up for the Windows Azure Free Trial. The free trial will costs nothing and it doesn't obligate you to buy anything at the end of it.  It provides an easy way to try out and get started with Windows Azure. The free trial provides everything you need to get started with Windows Azure. 
You receive a $200 credit to spend on Azure services during the trial. You can use this $200 however you want to create and try out any combination of Azure resources. It enables you to explore Azure cloud entirely for free.

If you exceed your $200 free credit, or your one month is up, your free trial account gets suspended . You can optionally upgrade your trial to be a Pay-As-You-Go Azure subscription at this point if you want to continue using and paying for services. If not you won’t be billed anything.

Remember that you have only 1 month and $200 credit to try out the Windows Azure. Use your credit and time wisely. Remove any running instances at the end of each day or whenever no longer in use. 

You need to provide three things for trial subscription:
  • The Windows LiveID account you want to use to use to sign-in and manage your account
  • A mobile phone number to get  a verification code.
  • A credit card

The credit card is not billed and during the free trial you’ll have a spending limit set to $0.  Spending limit ensure that you never have to worry about accidentally going over the resources included in a free offer and being charged.  If you end up building an application that exhausts the monthly amounts included in the free trial before the month ends, and you have a spending limit set to $0, then Windows Azure by default disable the application for the remainder of the month (leaving your data in read-only mode) . This ensures you are never billed anything during the free trial. 
You can remove the spending limit if you want to continue using the Windows Azure services. In this case, any usage in excess of the monthly allocation will be charged at standard rates.

There are some free trial account usage limitation that you can get from the following link :
http://www.windowsazure.com/en-us/offers/ms-azr-0044p#header-3

Clicking on  the link http://www.windowsazure.com/en-us/pricing/free-trial-b/ will take you to a sign-up page that enables you to quickly register a new account and get started with Windows Azure.


Option 2 :  MSDN Subscription
MSDN subscribers have azure benefits included with their subscription.

There are several ways to get an MSDN Subscription:
  • Purchase one of Visual Studio subscription offers.
  • Qualify for the Silver or Gold ISV Competency (or other competencies)
  • If you are a startup, join BizSpark.
  • Or if you are in an enteprise, there’s a good chance you already have access to it.
Once you have MSDN subscription, Log in to MSDN subscription site(http://msdn.microsoft.com/nl-nl/subscriptions/aa336858.aspx) using your live id which is mapped to your MSDN subscription. Then click on My Account ,you will see list of Subscription benefits, from Windows Azure section, click on "Activate Windows Azure" hyperlink, this will guide you how to use MSDN Subscription with Azure.

For the first month after activation of your benefit, you receive $200 of Windows Azure credits. After the first month, you receive $100 of Windows Azure credits every month.

Check the following link to see all the benefits available to MSDN subscribers 
http://www.windowsazure.com/en-us/pricing/member-offers/msdn-benefits-details/


Option 3 : Windows Azure BizSpark
Windows Azure provides great benefits for BizSpark members. BizSpark members automatically receive the Windows Azure benefit through their Visual Studio Ultimate with MSDN subscriptions. These benefits include $150 monthly credits of Windows Azure, lower rates and no additional charge for using MSDN software on Windows Azure. In addition, BizSpark members retain production use rights under this Windows Azure benefits offer. Not a Bizspark member

Option 4 : Windows Azure Pass , Windows Azure academic pass
More details can be found here :


Option 5 : Pay as you go
No commitment. Pay for what you use each month. This offer is billed at the standard Pay-As-You-Go rates. The Pay as You Go plan offers flexibility with no upfront costs and no long term commitment.  You will be notified at least 30 days in advance of any changes to the Pay-As-You-Go rates. New services may be added periodically to the Windows Azure platform.