Fragrance Of Programming
Traditionally web application are deployed to the server and published either publicly or internally. Prior to cloud, deploying web application was quite a long and tedious process and you need to have a proper infrastructure to deploy it. But with cloud service its very easy and even cheaper since now you don't have to worry about the infrastructure, everything will be taken care by the service provider. There are some pros and cons to it but this post is more related to deploying it to cloud, so will stick to the topic. So today I will show you how you can deploy the web application to azure using Visual Studio.
Visual Studio 2013 and up
Creating a Azure Web App
Navigate to Azure Portal, and login to your account or sign-up for the trial.
Once you are logged-in, you'll will see plus sign as shown below and clicking on that will give various option as shown below. Select "Web App" and then click "Quick Create".
Enter the valid URL and should be unique and then you need to click on CREATE WEB APP. Verify that site is created and its running.
Now switch to Visual Studio and when you are ready to publish your website, follow the below steps to publish
Download Publishing File
Publish Process in Visual Studio
The Settings page provides you an option to deploy as a Release or Debug as well as a place to define a database. Configure to suit your needs and select “Next >”
Finally the Preview page provides a view of all the files to be uploaded to your Windows Azure Web Site. Click on "Publish".
Visual Studio will give you a log of information as it deploys to Windows Azure. Once the above process is completed, navigate to the url which we created and you will be able to see the website, if there are no build issue.
Congrats, you have deployed your first web application to Azure.
I hope my post was helpful and please share if it was useful to you. Happy Coding.
Most of them might have heard about the new “async” and “await” keyword which was introduced in C# 5.0. Today I will be discussing about that feature and how it will fundamentally change the way we code. It will have a big impact on all our future application which we will develop.
Why it’s required?
As we all know, Asynchronous and Parallel programming is very important style and it mainly helps to perfect the responsiveness the application. Right from the first release of .NET, Microsoft is supporting this style and with every new release of .NET Framework new ways of asynchronous features were introduced. In all the previous version, we as a Developer used to write Synchronous methods and used to call them asynchronously using “Thread, ThreadStart, ThreadPool, BackgroundWorker, etc.” but writing asynchronous methods itself was very tough to do. So now with “async” and “await”, Developer can create asynchronous method very easily. In fact, asynchronous code can now be almost identical to its synchronous counterpart.
Asynchronous methods looks something like this:
The method above will run synchronously until the await expression is reached, at which point the method is suspended and execution returns to the caller. The awaited Task is scheduled to run in the background on the same thread. As a convention, asynchronous method should be named in the form of xxxAsync.
Async methods can return Task, Task<T> or void. Task is simply an implementation of IAsynchResult. When method returns Task<T> then it is awaitable and that means you can call it using keyword await to suspend itself until after the task is finished.
How to do it?
Now let’s see how we can create Async methods.
· First let’s open Visual Studio and create a new Console Application called AsyncFileProcessing.
· Add the below code in the Main function:
· Next create the ProcessAsync method that will run inside the task created in the Main method. And add the below code in that function
· ProcessAsync will in turn call the other async function called as ReadFileAsync and it will have a below code
· Now build and run the application. As you see we are awaiting the reading of File to be completed. In the meantime if you see Console is still responsive and user can type on it.
· Once the task is completed, you can see the below result.
In the above example under Main method we simply create the ProcessAsync method which we start and wait for it to finish. Now within ProcessAsync method we have the following statement:
var data = await task;
The above statement tells the method to start the task and wait till it’s completed. And when its waiting application is not freezed and it is still responsive. And similarly if you look “ReadFileAsync” we have the below statement:
data = await reader.ReadToEndAsync();
Above statement reads the file data asynchronously.
Rules and Limitations
While usage of async and await is very flexible but still there are some limitation which we need to take care of. Below are the notable ones.
· In C# 5.0 you can’t use await in catch and finally block. Things have changed in C# 6.0 and Developers can actually use await in catch and finally block.
· Constructors and property accessors cannot be marked as async and use await
C# 5.0 and Framework 4.5 has taken a huge leap in terms of asynchronous programming and with new release of C# 6.0 more and more features are getting added in terms of Async programming. In the upcoming tutorial I will try to cover some additional async programming features.