Enabaling BASH shell on Windows 10 Anniversary Update


Windows 10 Anniversary Update is already out and millions of PCs getting updated. Whole load of cool features were added on this update. For me the star features is the BASH shell for Windows 10. By default it doesn’t get enabled. I assume you already have this great update. If yes, lets go through the steps to enable this great feature.

First things first, you need to enable the developer mode of Windows 10 to enable this feature. Simply open the Settings window (or tell Cortana to open it for you). In the Settings window click on the Update and Security button.

Settings Wiindow

In the Update and Security window, select For Developers in the left side pane and click on the Developer option in the right side pane (You might have to restart the PC after this change). This change will enable you few things on your Windows 10 PC. For the moment I just focus on one feature that enables you the Ubuntu BASH Shell.

Now open Control Panel (or let Cortana do the dirty work for you) > Programs > Programs and Features.

Now click Turn Windows Features on or off and scroll down the dialog box. Select Windows Subsystem for Linux (beta) and click OK. This will install what you need and will require to restart your PC. You are ready to rock after this step.

Few more things to do before we get started. Lets open a command window. Type bash and press . Now type “y” to continue. Wait for few minutes till Windows Store installs Linux Subsystem.

Installing BASH

After a successful installation, give a username and password to continue.

User names and Passwords

Now you are good to go. Lets try out some BASH commands in ubuntu, like to check what is the version of ubuntu. Type

Here is the output. We have Ubuntu 14.04.4 LTS

Ubuntu Release

Its real Ubuntu Guys… I just did a apt-get update and look at the results.


Have a nice day. !!! 🙂

Merge Two Arrays – The LINQ Way

I just came across a requirement of  merging two arrays of integers. So I already had this integer array and there was a new array of same type and required merging those two. Yep remove any duplicates as well.

Line 4 of the Code

It just says add idList2 to idList1 and remove of any duplicates and convert the output to an array. In this case to an Integer array.

Output Window

Output Window

Happy Coding !!! 🙂

Everything you need to know about ASP.NET 5 Project Template

Its been a quite while that ASP.NET 5 is out there. Idea of this post is to help migrate to the new project template that comes with Visual Studio 2015. Lets get started.

OK, first things first.. lets get started with a new project. In the Visual Studio 2015 just >

New Project Template Dialog

In this dialog box make sure you have select ASP.NET Web Application and fill in the details.

Name : MyFirstASPNET5
Location: Where your project files gonna store
Solution name: MyFirstASPNET5

And click OK.

In the New ASP.NET Project dialog box select Web Application under ASP.NET 5 Preview Templates option. (NOTE: ASP.NET 5 is still on its preview stage.).

New Project Dialog

For the moment we are not going to create any test projects for this tutorial. After selecting Web Application under ASP.NET 5 Preview Templates click OK button. Visual Studio might ask you to create a Azure Website using this project template. If you do not wish to create a Azure Website just click Cancel in the next dialog box. Now wait for few seconds till Visual Studio create the base template for you. This base template is a starting point for your ASP.NET 5 Web Application. And its a fully working start point for you. By just pressing you can go through this base template.

This is how it looks like
Base Template

Press for a quick preview of this template up and running. (ASP.NET5 running on Microsoft Edge)
ASP.NET 5 on Edge

OK, so far everything is working fine and lets close the browser and go through the Solution Explorer. By default you should see the Solution Explorer is in the right hand side of your Visual Studio 2015 window. If not click View > Solution Explorer or just press CTRL + ALT + L 

View Solution Explorer

The Solution Explorer

The Solution ExplorerASP.NET project template will look like this. It might not change a much when the full release is available. As you remember a total new way of keeping the configurations and the folder structures.

You have a Solution Items folder that holds the global configurations for the solution. Yep you are correct its a JSON file. Also you get these References for your project as usual. And a whole new wwwroot section to hold the static files. Again as usual Controllers, Models and Views. And a Dependencies for your project dependencies.

And code first Migrations are enabled by default and it got is on folder in the root level. And all other JSON configuration files.

Finally a whole new folder for the Services you use, such as sending emails from you web application.


This file contains mainly two parts. The detail of the project and the sdk used by the whole solution.

Source FolderThe projects property has values to tell where your source code is stored. By default it stores under a folder named src . All your source is stored under this folder. Yes you can change this name without any problems. This will help all the build artifacts to store in the different folder named artifcats  and can be easily omit from the source controlling. Can keep your code much more organised by default. Cool isn’t it.

And sdk will store the version of the DNX (.Net Execution Environment) which Visual Studio will use it when you load the solution. Yes you can store different SDK values in the project.json file for different projects that use different versions of SDKs in the same solution.

wwwroot section

wwwroot SectionThis sections stores all your content files. As you see it has css, images, all your javascript files and the different libraries you use to make your development much more easier.

In the previous versions of ASP.NET the web root was the project root of the solution. It allowed to access all the static files as well as the configuration files such as web.config and global.asax. For protecting these configuration files you had to write specifically to protect these files. Also known as blacklisting.

But creating a separate section for all these static files in this new template and make it your root of the site. You do not need any extra effort for protecting. wwwroot just contains all the static files and other content that needs to start off your website.

Apart from the security this separation will simplify the minification and bundling of your static files such as css and javascript files.


Client side dependencies The Dependencies section will hold all he client side stuff that your project will depend on. It has two folders, Bower and NPM. These folders hold two package managers (like NuGet) with corresponding names. These two will pull all the dependencies as per seen in the image.

The bower dependencies are controlled by the bower.json file.

As you see each dependency can be controlled separately within this file. Also indicating how it should be deployed to the wwwroot folder when the bower task is executed.

NOTE: All the server side dependencies are controlled under References section. 


ASP.NET 5 no longer stores its application wide configuration settings using XML. Previously this file is known as web.config. All these settings are stored under config.json using JSON format. By default the file should look like this (at final release the content might change).

Again there is nothing fancy or you must have this file for your configurations. Not like ever growing web.config file you can have separate configuration files in a project. This main file by default accessed using Startup.cs in your root folder.

As you can see in the Startup method the builder variable collects all the configuration files you have in your project. So you can keep all your configurations in separate files for easy access and for maintainability and for the readability.


ASP.NET 5 introduces a few concepts that didn’t exist in previous versions of ASP.NET. Rather than working with web.config, packages.config, and a variety of project properties stored in the .csproj/.vbproj file. And developers can work these separate folders and files for maintainability and for security. Yes there will be a learning curve and its worth it !!!

Running ASP.NET 5 and Visual Studio Code for MAC

Visual Studio Code

ASP.NET 5 is around the corner for few months now.  A big excitement is how to run ASP.NET 5 in a MAC Box or under a Linux flavor. In this post I am focusing on running ASP.NET 5 application in a MAC Box. In a Linux Box like Ubuntu should be the same.

What you need?

  1. Install ASP.NET 5  and DNX in your MAC
  2. Visual Studio Code for MAC (Yes it true you have a Visual Studio version for your MAC Now)
  3. YeoMan for MAC (This is a web scaffolding tool that runs in a shell. You need this to create the base ASP.NET 5 project template)

OK, Lets get started

1. Install ASP.NET 5 and DNX in your MAC

We require a package manager called Homebrew. Open your terminal app and using this shell command install Homebrew. 

Wait a few seconds and follow the install instructions, you have Homebrew installed.

Open your terminal application and execute these commands to install ASP.NET 5 to your MAC.

Now you need to set some environment variables to get things smooth. Use your favourite editor to do this. I used vi to edit my .bash_profile file.

and add these lines and save the file.


now do an upgrade (a good practice if anything updated to the binaries).

2. Installing Visual Studio Code for MAC

From the above link visit Visual Studio web site. And you will a blue box to the left and click the download link to download and install Visual Studio Code for MAC OSX. After installing and running for the first time Visual Studio Code will look like this.

Visual Studio CodeNow lets get focus on installing YeoMan for MAC. This is not a must requirement, but its recommended you have this. Using this nice little tool you can scaffold the project template for ASP.NET 5. Yep there is a small catch to do this, there are few little things to be setup before installing YeoMan. To install YeoMan you will need NPM and to install NPM you need NODE. NPM is the package manager for NODE like you use NuGET on Visual Studio Projects.

Installing NODE and NPM

Now its time to install NODE and NPM. In your terminal window run this shell command.

Wait and relax a few seconds (may be few minutes depending on your connection) , NODE and NPM are installed for you. To check all are fine just run these two commands in the terminal window.

If you see these two outputs in your terminal, YAY !!! you have NODE and NPM installed and you are ready to rock.

Terminal, NODE and NPM

3. Installing YEOMAN for MAC

Let us install YEOMAN now and few tools required along with it. Again in your terminal window, execute this shell command.

OK cool, we are almost there to create our first ASP.NET 5 project on MAC OSX. Lets check YOMEN installed. Just execute this simple command in your terminal window and see the output.

YO Terminal

OK, you see Aspnet in the list. This because I have already installed ASP.NET generator. You might not see it in the first installation. To install ASP.NET generator, execute this command in your terminal window.

This will get you ASP.NET 5 project template scaffolding to YOMEN by OmniSharp. Now you will get the same menu as above screenshot when you execute the command “yo”.  To create base template for ASP.NET 5, execute this command in the terminal.

In the menu select an option to create the base template. Select Web Application and press

ASPNET 5 Template

If there is no ASCII art  in the command shell, you don’t get the true feeling of the shell 😀

Answer the project creation questions along the process. After a successful flow your folder should look like this.

LS on ASPNET folder

Now you have a base project templates. But you need one more thing to get this run. Lets get update all the NUGET packages and dependencies. In the terminal inside your project folder execute this command.

Now we are done with creating the base project template for ASP.NET 5. Lets get switch to Visual Studio Code for MAC and open the folder under Explore icon. After that click on the blue Open Folder button.

Visual Studio Code - Open Folder

Lets just browse through the files, see all the beautiful syntax highlighting and code completion built in for Visual Studio Code for MAC.

Code Completion

Now lets start the WEB SERVER  that will execute the ASP.NET 5 code. Click View > Command Pallet or press [APPLE KEY] + P and start typing “dnx: kestrel” and Visual Studio Code will complete the command for you and press . This will start the kestrel server for you to run the ASP.NET 5 project.


Server is Started

Server Started

Now open up your favourite browser and in the address bar just type

If everything goes fine and you have followed the instructions correctly you must see this screen.

ASP.NET 5 on Safari for MAC


Wait a minute, What if you see this screen (OH! NO WHAT WENT WRONG !!!)

OH!! No

Don’t worry its a known bug in Mono. This command in the terminal will help you to fix it.

Now start the server again and you are good to go !!!

The Default Route

When you press to debug an ASP.net MVC application you will see the URL is simplified and easy to understand and can use as a navigation as well. For an example when you click on the “About” link of the default ASP.net MVC application you the URL visible will look like this.


As you see after the domain name (in this case the localhost with the port number) it says Home and the forward slash and About. So it looks like you might have a Home folder and then About folder and there is no file name given end of the URL (ex: About.aspx). But you have a page displayed. If you wonder how this is possible, the trick is under routing.

OK, where this is handled?

Click on the Solution Explorer and expand your web project (in this example WebApplication5) and expand App_Start folder. Double click on the file, named RouteConfig.cs


Now scroll down to the code that looks like this

From line 7 to 11 you will see the route collection is being added. This is called the “Default Route”. It has three parameters

name: Name of the the route, in this case its “Default”

url: Which is the pattern of the URL that this route will create. {controller} represent the actual Controller of the MVC application. In this example its the HomeController and {action} represents the action within the controller again in this one its the About action within the HomeController and {id} is the parameter that takes in to an action method with in the controller.

defaults: These are the defaults values to replace above url pattern. And its self explainary. And says id parameter is optional.

Good Day !!! 🙂

Choosing an ASP.net Flavour

At the beginning there was only ASP.net Web Forms. Now you have three different models to choose with.

  1. ASP.net Web Forms
  2. ASP.net MVC
  3. ASP.net Web Pages

ASP.net Web Forms

These are set of pages that has a UI (User Interface), Server Controls and Server Code. When a user sent a request to the page using the browser, it goes to the server,  then compiled and executed at the server side. Finally generates HTML markup that can be rendered on your browser. If you are a experienced Windows Forms developer its a good choice to choose Web Forms. It is the event driven world that you already familiar with.

Server Controls such as Button, Grids, Labels, DropDowns can be easily dragged and dropped to your design and start coding like you did with Windows Forms.   To write server code to handle the logic for the page, you can use a .NET language like Visual Basic or C#.

More details on ASP.net Web Forms


The MVC stands for Model View Control. This is a design pattern most developers are familiar with. This is a light weight framework that can be used with ASP.net features such as Membership based authentication and Master Pages. This pattern separates your application into three parts. The logic of the application goes under Model. The presentation layer goes under View and finally talking between model and the presentation layer goes under Controller. Again to write code and handle the logic you can use a .NET language like Visual Basic or C#.

More details on ASP.net MVC 

ASP.net Web Pages

This flavour gives you a taste of script based programming like you did with classic ASP or PHP. A special syntax called Razor will escape your HTML code to dynamic code using a .NET language like Visual Basic or C#. If you know HTML, CSS and little bit of JavaScript and you have programmed with a .NET language like Visual Basic or C# and you are ready to start building ASP.net Web Pages.

More details on ASP.net Web Pages 

Have a Good Day !!! 🙂

Extending ASP.net Identity in an ASP.net MVC 5 application

A typical ASP.NET MVC application comes with a system for User Registration, Login and other elements you need to control your website that uses an user management system. This is more than enough for a typical website. In some cases you might need to extend this functionality. For example add few fields to your Registration Form. Before starting this tutorial make sure you have downloaded and installed Microsoft Visual Studio Express 2013 for Web (Link: http://bit.ly/1gNqqvJ). If you already have it or you have another Visual Studio 2013 version no problem lets gets started and skip the downloads.

Why Express Editions ?

Express editions are FREE to download from the Microsoft. Can be easily grab and install using above link. Express edition has everything you need to complete this tutorial. And this tutorial uses Microsoft Visual Studio Express 2013 for Web.

OK, Lets get started

First of all let us build a new project using Microsoft Visual Studio Express 2013 for Web. Lets click >

New Project

In the window, expand Templates and then Visual C# and select Web. In the Templates pane select ASP.net Web Application.  In the Project Name text box type a project name. In my demo I gave IdentityDemo. Now click OK

New ASP.net Project

Now you will be presented with New ASP.NET Project dialog box. Now select MVC in the Select template: area and make sure MVC check box is checked, under Add folders and core references for: section and finally click OK.

Now you have everything to test this demo. To confirm everything is working fine. Press , and the default project will be compiled and launched in the default web browser. If everything is OK you should see this screen.


Lets click on the Register link to see what we have there. A default registration page will be displayed. This registration form has only a user name and a password (yes confirm password too). So its a basic registration form. What if we need to capture more data. For an example I need to capture an email. How do I add this to the default registration system without breaking it.

Registration Page

Lets get an user registered here and check what is the default system has to offer. Like a normal registration form type a user name and a password and click the Register button. After a few seconds you get registered and logged in to the system.

Hmm, what happened in the background ?

At this moment you must be wondering whats going on in the background. Where is the database, where is these data stored. How do you check these data. By default ASP.NET MVC 5 project template has connection to a local database file under App_Data folder in the Solution Explorer. By default you wont see anything under there. First you need to click the icon Show All Files. This will show all the files that not included in to this project.

Show All Files

Now expand the App_Data folder. You will see a MDF file with the project name and the date. Double click on this file and you will able to see the structure of the database and its tables. You will notice (Server Explorer will be opened with your database). If you have used or familiar with ASP.NET Membership and seen tables created. But ASP.NET Identity has created a different set of tables and there are no more long names, stored procedure and views. Spend some time exploring these tables.

Database - SE

As you see under Server Explorer under Data Connection and you expand the Default Connection. Default Connection is the connection string name to your database. The table names are straight forward and understandable. Now you have seen the database. Lets explorer the code.

By default all these elements are controlled by the AccountController.cs (in the Solution Explorer, expand the Controllers folder). And the models can be found under Models folder. And the file name is AccountViewModels.cs. Our goal is to add a new field to the registration form. For example we add a new Email field to the registration form. You may think simply add an Email field in the AspNetUser table and update the view. Thats what I thought in the first place. It doesn’t work that way. The Identity model is developed using Code First method. So we need to follow that method to add a new field.

OK, Where is these information stored ?

If you expand the Models folder. You will see and extra file than the AccounttViewModel.cs which named IdentityModel.cs which as two simple classes implemented.

OK lets look at the class. This is the class we gonna add properties to the user. In this case an Email address. This class inherits the IdentityUser which has the model for the AspNetUser table. This class implements the IUser interface. Again the class will be link the actual database to the ApplicaitonUser. This is the place where the connection has been made to the database and to the table AspNetUser. Lets add a property named Email to the class. The changed code will be.

So far so good. Now Lets modify the code at AccountViewModel.cs and add the new Email field. The class we going to modify is . Why we doing this? Because, type is used to generate the Register.cshtml view, which is a strongly typed view of type. All the validation code can be implemented here. Lets see the modified code of the .

The new field added in to the class (see line 18, 19 and 20) also validated and given an error message.

Now lets go and modify the View for the registration page to reflect this change. Expand the Views folder under solution explorer. Again expand Account folder. Now double click on the file named Register.cshtml. This file has all the necessary code for the default registration system. Now we are going to add the new Email field we created. This is how this file looks by default.

Lets add the below code to the Register.cshtml below confirm password field (this is after line 31 in above code, or any place with in the form).

OK, we are ready to test our code. Simply press to test our code. All seems to be good. Site loaded without and compile error 🙂 and now click on the Register link. YaY !!! you can see the new email field is added. With all the validation stuff working.

Email field added

Lets just type some valid information and click the register button.


OK all the happiness just we had is gone. A runtime error has been thrown. What does this error message means. In simple words its says “OK, dude you have added a field in the class remember? Its not in the database duh!!”

Ah, OK Shall I go and modify the database and check?

No, you cannot. Remember at the top of this post I have mentioned ASP.net Identity is implemented under CodeFirst approach. We need some help from out side to update the database using newly made changes to the class. Where can we get this help? Yes you already have the correct tool in the Visual Studio it self. Lets open the Package Manage Console by using > > . This will open the . In the console prompt type with - parameter and press . After a successful command console window will look this.


Now you have enabled the CodeFirst migrations. Lets update the database issuing command. And after a successful command the console window should look like this.


Have a look on the Server Explorer and expand the database. You will see the newly added field is there.


OK, we are almost done. Lets not get excited yet. We need one more change to be done to store the newly added email data to the database. Lets open the AccountContoller.cs  in the Solution Explorer under Controllers folder. Move to the override method (action) of Register (which has the HttpPost attribute).

Change the code in line number 8 to reflect this

Phew !!! we are done now. Press and test your code.

Congratulations Coder !!! You have just extended the ASP.NET Identity  🙂


How do I print “1” as “0001” ?

Yep, a nice little question. Some of you may have wondering how to do that. In my database ID field it says “1” (or any integer value) on my Web Page or Windows Form I need to print this as “0001”. Do we have a simplest method to do that? And the answer is (drum roll) ….. YES ..

OK, next question what does this format specifier “D” means. Here is the MSDN help about it.

The “D” (or decimal) format specifier converts a number to a string of decimal digits (0-9), prefixed by a minus sign if the number is negative. This format is supported only for integral types.

The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier. If no precision specifier is specified, the default is the minimum value required to represent the integer without leading zeros.

Also we can use another string method known as . Lets have a look on that code.

allows you to apply any character (type of Char) as the leading character. In this case ‘0’

Have Fun 🙂