Wednesday, July 16, 2014

Part 14 : Windows Azure Web Sites - Scaling

In this tutorial we will see how you scale your website up or down depending on the needs.

Scalability is the ability of a system to handle a growing amount of work in a capable manner or its ability to be enlarged to accommodate that growth

When you start developing a new web application, or when you want to test your web application, or try out the Azure WAWS, you might want to start free and small. All web sites can deploy in a free hosting mode. Then as the traffic to your website increases and as the expectations for performance and availability increases, you can scale out to meet the needs of your business.

Also if your website is already in production and you have some period of time where you expect the hits go high, for example gift shopping website during the Christmas season, you can scale up for that period of time and then scale down again later.  Consider the situation where you have your own servers in datacenter, you have to provisions the servers for the peak load and most of the times the servers will be lying ideally but incurs cost to you. With cloud, this is great feature to scale up and down depending on your needs and can save lots of money.

By adding and removing role instances to your Windows Azure application while it is running, you can balance the performance of the application against its running costs. You can add new instances when demand is high, and remove instances when you no longer need them in order to reduce running costs.

For increased performance and throughput for your websites on Microsoft Azure, you can use the Azure Management Portal to scale your Web Hosting Plan mode from Free to Shared, Basic, or Standard.

Scaling up on Azure Websites involves two related actions: changing your Web Hosting Plan mode to a higher level of service, and configuring certain settings after you have switched to the higher level of service.

Each scale operation happens quickly – typically within seconds – and does not require changes to your site’s code, nor a redeployment of your site. Scale operation have no impact on existing user sessions.
You can also scale up or down programmatically by using the Windows Azure Management API.

Before moving forward let's see what exactly is meaning of scale up and scale out.

Scale Up
Also know as scale "vertically". You can scale up by increasing the processing power by adding more processors and RAM or buying a bigger, multi-core robust server.
Pros : Less licensing cost, less power consumption than running multiple servers, less challenging to implement.
Cons : If single server fails, it brings down the whole application, price.

Scale up operations can be performed on any site without worrying about the implications of multi-instances data consistency.
Windows Azure offer servers for web sites in multiple instance sizes of small, medium and large. Scaling up in Windows azure for web sites can be achieved by changing the instance size of the server, e.g. from small to medium.








Scale Out
Also known as scale "horizontally". You can scale out by adding more servers and adding a load-balancer to distribute the demand between them.
Pros : cheaper than scaling vertically, easier to run fault tolerance
Cons : More licensing fees, higher utility cost, complex to implement.

To scale out your site in windows azure, you need to just increase the instance count for that web site. This is very easy and we see it in practical shortly.  The big advantage with Windows Azure is that when you scale out a web site in Windows Azure Web Sites there is no need to configure load balancing separately since this is already provided by the platform.

To benefit from scale OUT operations your site must be designed for concurrency. You should plan for the shared state so that request from particular user can be handled by any server under the load-balancer. Or use sticky session. Sticky session means that when a request comes into a site from a client all further requests go to the same server initial client request accessed. Load balancer will usually handle this.

One thing to understand regarding scale out is that even they can increase the total amount of traffic capacity that your site can handle, it does not always improve performance in the way that scaling up does.

Scale up and scale out operations can be combined for a website to provide hybrid scaling. The same contentions about multi-instance sites would apply to this scenario.

Let's start with a free website and we will scale it using Windows Azure Management Portal.

Scaling of Free website to Shared or Basic mode
1. Open Management portal and create a website in free mode (if not already created). Assume that your      website is currently in development mode and this is the reason we choose free mode.

 2. In the website listing page, click on the site and then go to "Scale" tab.












 3. Currently the website mode is free. Now our website goes into a test phase where business users and stakeholders are going to test the website. So we are going to scale it to Shared mode. The Web Hosting Plan Sites section shows a short list of sites in the current plan. All sites in the current plan will be changed to the Web Hosting Plan Mode that you select. Click on the Shared mode. Under capacity let the instance count be 1 instance and click on save. Note that in free mode you cannot change the instance count.
So now effectively we have scaled up the website to shared mode. 

4. Now testing is done and accepted by business users. We want to roll out the pilot site for several hundred users and we want  the website to available for most of the time. What we can do is to let the site remain in shared mode but increase the instance count. Again go to website and then scale tab and then in the instance count make it 3. You can scale out to maximum of 6 instances. Windows azure will automatically configure load balancer for you. Notice that in shared mode you can increase the instance count but not the instance size, because it is fixed in shared mode. So you can scale out but not scale up.  Also note that while changing the web hosting plan mode will change all the website under that plan , changing instance count will not affect the instance count of other sites in the same web hosting plan mode. 
Still confused :) try it out yourself and you will understand.


 5. Now our pilot phase is well received by audience and we want to go into production. But we don't want to go into production in shared mode. So we want to change it to Basic mode so that we will have dedicated servers serving only our website. Go to the scale tab again and this time choose the web hosting plan mode as Basic. You notice that there will be one more configuration item available "instance size". Now since we have our own reserved server, we can also choose the right fit size that we want. Since I just launched my website I want to start with medium size server and two of them to support availability. This is the example of hybrid scaling where we both scale up and scale out. 


Also notice that changing the instance count or size will change for all the sites in web hosting plan, which is little different that shared mode as described above.

6. Now suddenly the management decided that there are some serious business flaws in the current website and they want to fix it but at the same time they don't want to incur cost during that time. Easy, just go to scale tab again and choose the web hosting plan mode as "free" and start your development.

So we have seen how easy it is to scale up or down as required in Windows Azure and these changes take only seconds to apply.
Scaling Website to Standard Mode
Before going into this topic lets discuss Auto-scaling briefly. One of the key benefits that the Windows Azure technology platform delivers is the ability to rapidly scale your application in the cloud in response to changes in demand. If you rely on manual interventions to scale your application, you may not always achieve the optimal balance between costs and performance; an operator may respond late, or underestimate the number of role instances that you need to maintain throughput. An autoscaling solution reduces the amount of manual work involved in dynamically scaling an application. It can do this in two different ways: either preemptively by setting constraints on the number of role instances based on a timetable, or reactively by adjusting the number of role instances in response to some counter(s) or measurement(s) that you can collect from your application or from the Windows Azure environment. We will see the autoscaling feature in this topic.

NOTE: Before switching a Web Hosting Plan to Standard mode, you should remove spending caps in place for your Microsoft Azure Websites subscription. Otherwise, you risk your site becoming unavailable if you reach your caps before the billing period ends. 

1. To scale to Standard, follow the same initial steps as when scaling to Shared or Basic, and then choose Standard for Web Hosting Plan Mode. As before, the Web Hosting Plan Sites section shows a short list of sites in the current plan. In this case, all sites in the current plan will be changed to Standard mode.

2. Selecting Standard expands the Capacity section to reveal the Instance Size and Instance Count options, which are also available in Basic mode. The Edit Scale Settings for Schedule and Scale by Metric options are available only in Standard mode.

3.  Configure the Instance Size and instance count as we have seen before.

4.  If you want to automatically scale (autoscale) resources based on daytime versus nighttime, weekday versus weekend, and/or specific dates and times, choose Set up schedule times in the Edit Scale Settings for Schedule option.


5. A new dialog box called "Set up schedule times" will open.  The Set up schedule times dialog provides a number of useful configuration choices. These options let you define different scale settings during weekdays or weekends.

First checkbox is "Different scale settings for day and night". This creates two schedules. The first schedule runs from the start of the day to the end of the day. The second schedule runs from the end of one day to the start of the next day, and uses the options below to define times and the time zone.


Second checkbox is "Different scale settings for weekdays and weekends". This creates a separate profile that starts on Friday evening and ends on Monday morning. Use the options below to define start times, end times, days, and time zone.

Under Recurring Schedules, select Differing scale between Day and Night and/or Differing Scale between Weekday and Weekend to scale resources based on separate daytime and nighttime schedules and/or separate weekday and weekend schedules. For the purposes of this feature, the weekend starts at the end of day Friday (8:00 PM by default), and ends at the beginning of the day on Monday (8:00 AM by default). The weekend profile uses the same day start and end that you will define in the Time setting. 


Under Time, choose a start and end time for the day in half-hour increments, and a time zone. By default, the day starts at 8:00 AM and ends at 8:00 PM. Daylight Savings Time is respected for the time zone that you select.

Under Specific Dates, you can create one or more named time frames for which you want to scale resources. For example, you may want to provide additional resources for a sales or launch event during which you might have large peaks in web traffic. Please note that this will override your other scale settings.

After you have made your choices, click OK to close the Schedule Times dialog box.

6. The Edit Scale Settings for Schedule box now displays configurable schedules or events based on the changes you made. Select one of the recurring schedules or specific dates to configure it.


You can now use the Scale by Metric and the Instance Count features to fine tune the scaling of resources for each schedule that you choose.

7.  To dynamically adjust the number of instances that your website uses if its load changes, enable the Scale by Metric option by choosing CPU.


The graph shows the number of instances that have been used over the past week. You can use the graph to monitor scaling activity.

8. Scale by Metric modifies the Instance Count feature so that you can set the minimum and maximum number of virtual machines to be used for automatic scaling. Azure will never go above or below the limits that you set. This enable you to proactively set the number of role instances that your application can use; the minimum number of role instances helps you to meet your service level agreement (SLA) commitments, the maximum number of role instances helps you to control the running costs of your Windows Azure application.

9. Scale by Metric also enables the Target CPU option so that you can specify a target range for CPU usage. This range represents average CPU usage for your website. Windows Azure will add or remove Standard instances to keep your website in this range.

Note: When Scale by Metric is enabled, Microsoft Azure checks the CPU of your website once every five minutes and adds instances as needed at that point in time. If CPU usage is low, Microsoft Azure will remove instances once every two hours to ensure that your website remains performant.



Tuesday, July 8, 2014

Part 13 : Windows Azure Web Sites - Basics 2 - Web Hosting Plan mode

Windows Azure Region
We have seen in the previous tutorial that we have to select the region while creating a website in Windows Azure Management portal. Windows Azure uses the idea of regions to manage the physical distribution of your applications and data. A region represents a Microsoft data center where you can deploy your application. There are many regions available in Windows Azure like Asia, Europe, North America and it keeps on increasing.


Choosing a region will have direct impact on Network Latency. You want to deploy your application to the data-center that is closest to your user base. Also you want to replicate your data across multiple regions so that if one region or data center is offline, your application still be available. Windows Azure have options to deal with this (Traffic Manager, CDN) and we will learn  that in later tutorial.


Web Hosting Plan Mode
Web Hosting Plans can be shared across multiple web sites. Each plan has a mode associated with it. Different modes expose different sets of features and capabilities. Currently Azure Web sites is offered in four modes for hosting your websites : Free, Shared, Basic and Standard.

Shared mode is in preview feature as time of writing.  Plans in the Free and Shared modes run on a shared infrastructure with sites managed by other customers. These sites will have strict quotas for resource utilization. Plans in the Basic and Standard modes run on resources that are dedicated to your sites and have fewer restrictions.

Free
Free is the default scale for any website that is newly created in Windows Azure Websites.You can run upto 10 free websites in this mode. In Free mode your website is hosted on the same Virtual Machines as other sites (also known as multi-tenant hosting environment) and you cannot scale a single website on multiple web servers.  So the same server where your website is hosted can  be shared by many different websites. Shared means each website is taking up some amount of memory and utilizing some portion of the CPU.

Using this free mode, you can start your development and testing of websites at no cost at all. Obviously "free" comes with some limitations. In this case you can run websites that can serve 165MB of outbound traffic per day(5GB/month) , 60 minutes of CPU per day, per region. Storage is limited to 1GB.

Also with free mode, you cannot assign custom domain to the site. With free mode the site name will always be <sitename>.azurewebsites.net.

And yes one more thing, free site does not have any SLA.

Free mode is generally used by developers and testers during development.

Shared (Preview Mode)
Hosting website in this mode reduce some of the restrictive quotas associated with Free Mode, but computing resources are still shared.  Your website will still be hosted on the same Virtual Machine as other sites. In the Shared mode your CPU usage quota is 4 hours per day with storage limited to 1GB. The first 5 GB/month of bandwidth you serve with a shared web-site is free, and then you pay the standard “pay as you go” Windows Azure outbound bandwidth rate for outbound bandwidth above 5 GB.

You can scale out your website to maximum of 6 shared instances. Windows Azure will automatically configure load balancing for it.  In shared mode, you can set up multiple custom domain for your website rather than stuck up with .azurewebsites.

The price for the Shared tier during preview is $0.013 per hour (~$10/month). This price reflects a 33% preview discount.

Shared website also don't have any SLA.

Shared mode is good for personal sites or for the sites that doesn't have large amount of traffic and can withstand some duration of down time in case of crossing the quota.

I would like to point out here that it is very essential to have put quota on Free and Shared mode, so that one website should not eat up all the memory or dominate the CPU. And when I said CPU usage quota is 1 hour per day, that doesn't means that your website can be up only for 1 hour per day. That actually means is that your website can use 1 hour of CPU time in 24 hours. Your website needs CPU cycles only when it is serving some page requests, provided it's not coming from cache. Each request uses only seconds of CPU time. So it may be possible that your website is up for hours if traffic is low or use the quota in minutes if traffic is very high.

Remember that both in Free and Shared mode, once you cross the quota, any request to your website will be redirected to a page that tells that this site has exceeded the quotas. If this is your mission critical website or any website that generates revenue, you don't want this to happen. In this case you need to go for either Basic or Standard mode.

Basic
In Basic mode, you websites are guaranteed to run in a seperate VM which is dedicated for your website.
This option removes any need for the memory and CPU quotas since you are the only tenant on the machine.
You can choose the size of the VM Small, Medium or Large VM and you can run any number of web-sites within a VM. The storage is increased to 10GB for all your websites. You can also set up multiple custom domain for your website

Note that with this option all your website in that region or datacenter are hosted by the same reserved instance. There is no per site cost  in this mode. You pay only for the reserved instance you use and you can run any number of websites in that instance. You can choose between the small, medium or large instance.
So lets say you have very high traffic websites that require 2 large VM instance and another site with very low traffic, both will enjoy the benefit of 2 instance if they are in the same data-center(region).
So basically even though you are paying more, you can save by deploying multiple websites on an instance that is dedicated to you.


You can run sites on a single reserved VM instance or scale up to have multiple instance all running your websites. You can scale upto 3 dedicated VM instances. You can also scale up a single instance by increasing the size of your VM instance (small to medium or large). Windows Azure will automatically configure load balancing for it.

Standard
Everything we say about Basic mode is applicable to standard with more quota and features. In standard mode also, your websites run in a separate VM without any quota for CPU and memory. You can run any number of sites in that reserved instance. The storage is increased to 50 GB and Custom domains are supported.

You can choose between small, medium or large instance. You can scale up to 10 dedicated instances. You can also scale up a single instance by increasing the size of your VM instance. Windows Azure will automatically configure load balancing for it.

One of the biggest feature of Standard mode is Auto Scale. In other modes, you have to manually monitor the traffic and scale up or down based on the traffic (we can scale up or down through Windows Azure Management Portal, i'll show this in just a moment). Auto Scale allows you to dynamically adjust the capacity based on the load your websites is experiencing. You can set rules to trigger the scaling of your instances. For example, you can set a trigger that if CPU becomes overloaded , add one more instance, or you can also schedule it, on weekends increased the number of instance to 4. You can auto scale up or down your instances.

Also note that if you choose an option of reserved instance, all your websites under your subscription will be moved to the reserved instance. You don't have an option to run some websites in shared mode and other in reserved mode. If you wish to do that, you have to divide the websites in different subscriptions.


In the next tutorial we will see how we can scale websites up and down depending on our needs.


Monday, May 26, 2014

Part 12 : Windows Azure Web Sites - Deployment using Visual Studio 2013

This tutorial shows how to deploy an ASP.NET web application to an Azure Web Site by using Visual Studio 2013.

With the release of new Windows Azure SDK version 2.2 for Visual Studio 2013, sign in has been integrated directly within Visual Studio so that you can sign in to Windows Azure without ever leaving the IDE. This is great for developers as they now develop, debug and manage Windows Azure resouces from within Visual Studio. You no longer need to create and download the management certificates. One of the new feature is Remote Debugging, devlopers can now attach the debugger to running instance of Windows Azure cloud service right within Visual Studio. Remote debugging is great feature for developers as they can now debug a live cloud service which is very helpful if you want to track down any issues.

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.

Create a web application
1. Open Visual Studio 2013.
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 Web Application.  Ensure that .NET  Framework  4.5 is selected as the target framework.


 3. In the New ASP.NET Project dialog box, select the MVC  template, and then click Change    Authentication.

 4. Since this is sample application, we don't need any login. In the Change Authentication dialog box, click  No Authentication, and then click OK.

 5. If you haven't already signed in to Azure, Visual Studio prompts you to do so. Click Sign In.
     

 6. Enter the ID and password of the account that you use to manage your Azure subscription.
    

 7. When you're signed in, the Configure Azure Site Settings dialog box asks you what resources you want  to create. Visual Studio provides a default Site name, which Azure will use as the prefix for your  application's URL. If you prefer, enter a different site name.In the Region drop-down list, choose the  location that is closest to you. This setting specifies which Azure data center your web site will run in.Leave  the database fields unchanged as for this tutorial we are not using any database. Click OK.

8. In a few seconds, Visual Studio creates the web project in the folder you specified, and it creates the web  site in the Azure region you specified. You will get a message that your project has been created. The Web  Publish Activity window shows that the site has been created.

 9. If you go to the Windows Azure Management Portal, you can see the website listed under Web Sites    tab.

Though your website has been created, there are no contents yet. We need to deploy the site.

Deploy the application to Azure

 1. In the Web Publish Activity window, click Publish WebApplication1 to this site now. Publish Web  wizard will appears. The wizard creates a new publish profile that contains settings such as the web site  URL that Visual Studio needs in order to deploy your project to Azure. The profile is automatically saved  so that later when you make changes to the project you can easily redeploy the project to the same site.
 2. In the Connection tab of the Publish Web wizard, let the Publish method as Web Deploy. Change the  password if you wish and click on Validate Connection to make sure that Visual Studio can connect to  Azure in order to deploy the web project.

 3. When the connection has been validated, a green check mark is shown next to the Validate Connection  button.Click on Next button.

4. In the setting tab, you can accept the default settings on this tab. You're deploying a Release build and you  don't need to delete files at the destination server, precompile the application, or exclude files in the  App_Data folder. Click on Next button.


 5. In the Preview tab, click Start Preview. The tab displays a list of the files that will be copied to the server.  You can also skip this step and directly click on Publish button.



 6. Click on Publish Button. Visual Studio begins the process of copying the files to the Azure server. The    Output and Web Publish Activity windows show what deployment actions were taken and report successful  completion of the deployment.


7. Upon successful deployment, the default browser automatically opens to the URL of the deployed web  site, and the application that you created is now running in the cloud. The URL in the browser address bar  shows that the site is being loaded from the Internet.



How to redploy after making changes

1. Modified any file you want or add a new one.
2. In Solution Explorer, right-click the project, and choose Publish.

3. The Preview tab of the Publish Web wizard appears. If you needed to change any publish settings you  could choose a different tab, but now all you want to do is redeploy with the same settings. Click on Publish  button.

4. Visual Studio deploys the project to Azure and opens the site in the default browser.

There also a tool called Web One Click Publish tool, which is a quicker way to redploy. This toolbar is not enabled by default. To enable it go to Views-> Toolbars-> Web One Click Publish.  You can use it to select a profile, click a button to publish, or click a button to open the Publish Web wizard.


In this tutorial we have seen how we can use the integrated sign-in feature of Visual Stdio 2013 and deploy the application to Windows Azure. In the upcoming chapters we will learn more features of Visual Studio like remote debugging. 

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.