Choosing an Flavour

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

  1. Web Forms
  2. MVC
  3. Web Pages 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 Web Forms MVC

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 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 MVC 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 Web Pages.

More details on Web Pages 

Have a Good Day !!! 🙂

Extending Identity in an 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: 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 Web Application.  In the Project Name text box type a project name. In my demo I gave IdentityDemo. Now click OK

New 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 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  🙂


Where did they hide the web templates in Visual Studio 2013

For the first time when I loaded the Visual Studio 2013, just clicked on the “Web” label in the right side pane under Templates in dialog window, just felt OK where are my web templates.

New Project

OK, to get those now you need to go through one extra step. Just select on the Label “ Web Application”  and choose a folder and give a proper name to your project and click “OK”. The next dialog box has plenty of information you need know about your web application.

Select Template

1. This area will help you toe select a starter template. It has

Empty – A blank skeleton to start from scratch, You will need to add References, Folders for your project by hand.

Web Forms – A Web Forms project template will be created here. Most of the References you need to work with a Web Project will be loaded for you and all the necessary folders and files created. You will have a basic web site working here, to test just simply press “”.

MVC – This option will create a template with Model, View, Controller pattern. All the required folders, scripts and references will be automatically created for you. A sample web site is already ready for you to test. Simple “” will get you the sample web site up and running.

Web API – This template will allow you to create a RESTful HTTP Service. A broad range of clients will be able to access this service when you are done.

Single Page Application – A template that allows you to create a website with rich client JavaScript, HTML5 and CSS3. With a mix of Web API.

Facebook – A ready to run facebook application will be created with this template. A great template to start your facebook application.

2. An informative area of the selected template on area 1. A small description is displayed here for the selected template.

3. This area will allow you to add references or remove them on a selected template on area 1. If you select add unit testing, you will able to give the name for the testing project name here as well.

4. This button will allows you to select the authentication type of the selected project template type.

Enjoy 🙂