Author Archives: Imran Abdul Ghani

New Features in Visual Studio 2015 | 2013 | 2012 | 2010

Microsoft’s Visual Studio went through an enormous development in recent years. How it evolves since 2010 till the latest version i.e. Visual Studio 2015 is the purpose of this Web Development Tutorial. I’ll provide you a brief history of Visual Studio development with top features introduced with each version.

As it’s not possible to list each and every single new feature introduced in a specific Visual Studio version, I’ll list the top features that I personally like about it, so forgive me if I missed an important feature that you worked with. It’s better to comment at the end with your favorite feature that really improved your performance as a developer in your day to day activities.

Below diagram clearly indicates the evolution of Visual Studio in recent years.Visual Studio 2015 & 2013 & 2012 & 2010

As opposite to above diagram, I have explained/listed the features from top to bottom i.e. starting with Visual Studio 2015 and ending at Visual Studio 2010.

Visual Studio 2015

Visual Studio 2015 has been finally released including several incredible features that enhanced the way we look at development from desktop and web to mobile applications.

  • Improved Code Editor: The Code Editor has been already replaced with the so called “Roslyn” compiler to provide you an improved and exciting code editing experience. A light bulb is shown when you have to include some code fixes , so anytime you see a light bulb, click it and you will get suggestions that is based upon the analyzed code.
  • Custom Layout: The full potential of this feature can be used on multiple devices. Let’s say you are about to use a Surface Pro to develop on your bus ride home and a 24″ monitor from the comfort of your home. In order to quickly switch devices go to Window – Apply Window Layout. Keyboard shortcuts is also supported so that the user can quickly navigate to any familiar layout.
  • Shared Project: Probably you have been a witness of an event when you wanted to use a Shared Project option right outside of Windows Universal Application, now IT IS A REALITY. After a quick search you will find the Shared Project in the list of the new project window.
  • Single Sign-In: This one is undoubtedly much awaited feature. As these days, we developers, are using cloud services for multiple purposes. So, managing these services with different sign-in details in Visual Studio was annoying as authentication alerts were required for accessing these integrated cloud services. With Visual Studio 2015 single Sign-In support is provided, so once we are authenticated with first cloud service, no more authentication needed (Coooool…..).
  • Smart Unit Tests: IntelliTest in Visual Studio 2015 has the capability to explore our code to generate test data and a suite of unit tests with much improved code coverage.
  • Emulator for Android: No doubt the Android Emulator is a true relief as you can use it in Visual Studio 2015 as a cross-platform project or VS Tools for Cordova. It supports a variety of sensors and simulations, also GPS Location, Screen Rotation,  Accelerometer, SD Card, Zoom, Multi-touch, Camera and access to network also.
  • Renaming Enhancement: Before the user renames a variable or an object, Visual Studio will highlight all affected instances making it easy to identify all the changes to be made. Also there is a new dialog window that shows the number of changes or even conflicts for a renaming operation.
  • Editor Touch Support: There is an enormous boom of touch sensitive devices and monitors nowadays, so Visual Studio 2015 had to come up with touch based support. You can use the touch screen for scrolling, gesture zooming, line selecting and also a new functionality was added to bring up the Editor context menu.
  • Support for JavaScript Editor: Working as a web developer on Microsoft Platform, it’s always been difficult to work with JavaScript within Visual Studio. Although Visual Studio 2013 has improved it’s editor for JavaScript but in Visual Studio 2015, JavaScript editor has been updated with number of amazing features as:
    • Intellisense support for object literal
    • Expand/Collapse JavaScript code sections
    • New Navigation Bar for navigating between elements in JavaScript
    • Support for New JavaScript Features (ES6 version)
    • and many more…
  • Custom Window Layouts: Most developers are familiar with their own window configuration. Let’s say you work on a JavaScript based project, then you will need a much larger code editor window whilst with a web project you may want to open the solution explorer window.

These are many other features introduced with latest version of Visual Studio. You can get a complete list of these Online at Visual Studio Website.

Latest Books on Visual Studio 2015

Visual Studio 2013

  • Throw-away applications: In Visual Studio 2013, the new project window looks a little different. If you want to create a new project, the name and the location no longer have to be set immediately. It is a good option when you are about to test something and delete the project right away, so you don’t waste time.
  • Code-lens: A feature that is available only in the Ultimate Edition. A real time saver, as by default, it shows the number of times a method or property is referenced in your code. Especially useful feature in larger project where you are not familiar with the entire source code.
  • Customizing Scroll Bar: The possibility to customize the scroll bar just gives the user a much better overview of larger files. A user can set the scroll bar to show breakpoints, errors and much more.
  • ALM (Application Life Cycle Management) features including agile portfolio management, web-based code comments, web-based test case management, change-sets and commits etc.
  • Creating Azure Website from within Visual Studio 2013 by installing Azure SDK and connecting to Azure.
  • Live debugging in Azure
  • Live Tracing from Azure
  • With .NET framework 4.5.1, just like 32-bit Edit and Continue, now we have with 64-bit also.
  • Better Navigation & Search
  • Open a method definition by using Peek a Definition feature.
  • Handy feature of resolving type by resolve menu.
Exam 70-486

Visual Studio 2012

  • While the Visual Studio 2010 already included an emulator for Windows Phone devices, the Visual Studio 2012 Simulator is much more powerful. It enables debugging apps for various scenarios that you just don’t have natively on your own machine.
  • You can also develop Windows 8 apps that strictly require some hardware support such as touch, rotation and different target resolution.
  • It is unimaginable to build quality applications without good IntelliSense. Therefore, the developers put enough effort in Visual Studio 2012 to make it more efficient and productive.
  • An even more important feature is the JavaScript Console. The good news is, that you can play with the source code modifications while the application is running.
  • Runtime Debugging Tool i.e. DOM Explorer for debugging HTML/CSS.
  • Asynchronous Support in C#/VB
  • Team Foundation Explorer Window
  • Code Clone Detection
  • Project File Compatibility with Visual Studio 2010

Visual Studio 2010

  • IntelliSense improvement: One of the most important and time saving feature. It is so comforting to wonder how many hours a programmer can save thanks to IntelliSense. For those who don’t know, it is that wonderful drop down list that automatically completes existing member names or type names. This feature can amazingly speed up your work as you don’t have to type so much on your keyboard.
  • Toolbar Items can be easily found: Each new version of Visual Studio has an exponential increase of items in the Toolbox. Until the release of VS 2010, the items where categorized into collapsible sections and searching was managed manually by the user. Fortunately, the new version of Visual Studio offers a search via keyboard.Simply click on the Toolbox so that it is focused and just start typing.
  • Improvement in Searching: Visual Studio always supported different search features , but the fact is that it was a little clunky. In other words, the search feature was limited to searching for specific string in files. This feature was still available but a new one was added. A search window called Navigate To. You can navigate anywhere in your project by typing in the name of a method, class, an event or even a file name.
  • Multiple monitors: It is statically proven that using multiple monitors can improve a programmers efficiency by 50%. So, visual Studio 2010 has feature for detaching window outside the IDE.
  • Highlighting References feature in Visual Studio 2010 can highlight all calls to a specific method or member variables.
  • Improved Loading Time for Assemblies in “Add Reference”.
  • Support for Targeting multiple .NET Framework during Application Development.

Hopefully this Web Development Tutorial helps to understand how Visual Studio evolve in recent years and what are the most exciting features introduced with every version. Now Visual Studio 2015 is available having lots of cool features that will definitely increase developers productivity in many ways.

Top 10 Tips to Get MCSD Certification

MCSD Certification Exams

MCSD (Microsoft Certified Solution Developer) Certification Exams validates the ability of the developer to build software solutions that cover platform boundaries as well as technology. In order to gain the MCSD credentials, a developer applicant has to pass a variety of exams, each of which is focused on a specific programming language, service or a platform. With constant shifts of technologies and changes, it’s quite difficult to choose a certification program that suits you the most. The best would be if one could select a program that is closely related to the current environment and applications they already have experience.

In order to simplify the things, I have listed all available tracks for MCSD Certification as:

  • MCSD Web Applications
  • MCSD SharePoint Applications
  • MCSD Azure Solutions Architect
  • MCSD Application Lifecyle Management
  • MCSD Windows Store Apps (C# & HTML5)

Following diagram further explains what specific exams you need to pass for every MCSD Certification Track.MCSD - Microsoft Certification Exams

Tips to Get MCSD Certification

To make it easier for you, we prepared the TOP 10 Tips to get your MCSD Certification:

  1. It is a necessity to have an organized study plan and try to stick to it as much as you can. Divide the study plan step by step and learn systematically.
  2. The exam must be scheduled, so that you will be able to set up your own deadline.
  3. You will need the MCSD Certification Toolkit that is a perfectly crafted guide to prepare you for the exam. It contains sample codes and features a step-by-step tutorial for each lesson containing over 100 simulated questions.
  4. Browse through this website http://www.microsoftvirtualacademy.com to participate in training lesson at the Microsoft Virtual academy.

    Also, you can find very helpful MCSD Certification Material on this website, specifically related to MCSD Web Application Development Track that include following exams:

    • Exam: 70-480 (Programming in HTML5 with JavaScript and CSS3)
    • Exam: 70-486 (Developing ASP.NET MVC Web Applications)
    • Exam: 70-487 (Developing Microsoft Azure and Web Services)

    You can find Reference Material, FREE Online Test and Real-Time Scenario-based Online Practice Exams here.

  5. All the questions are based around real world scenarios so practical experience will be more than just useful.
  6. A very good advice is to use mind map hierarchy. So you start off with a main topic having branches from it that leads to sub topics and so on.
  7. Practice as much as you can with the simulator so you get an overview of your performance.

    As mentioned above, we have prepared FREE Online Tests as well as Online Practice Exams, you can use to validate your skills before appearing for actual exams.

  8. Eliminate your incorrect answers.
  9. Never make a mistake to study only the main topic but try to focus around the topic as well.
  10. Try to take advice from members that already passed the exam.

Hopefully, the tips will be helpful as well as provide you a good plan of action for preparing your Microsoft MCSD Certification Exam.

Good Luck.


Available MCSD – Microsoft Certification Jobs

Microsoft Certification Jobs

Microsoft .Net Developers
Source: GotoGulf
Details: Microsoft Certified Professional will be a big advantage. Microsoft .Net Developers. Microsoft .NET framework using Visual Studio .Net, VB.NET, ASP.NET , C#,...  More
8 days ago

Sharjah 18-June-2017

IT Network Support Engineer
Source: Serco Group
Details: Microsoft Certified Solutions Associate / Systems Administrator certification (MCSA) or Microsoft Certified Solutions Expert / Systems Engineer (MCSE)...  More
30+ days ago

Dubai 04-May-2017

Programmer
Source: American University of Ras Al Khaimah
Details: Required Knowledge and Skills Bachelor in Information Technology or Programming Diploma any equivalent degree Preferred Microsoft Certified Database...  More
30+ days ago

Ras al-Khaimah 07-April-2017

IT Assistant
Source: JobAlert
Details: Preferred Cisco and Microsoft Certified. 2 years working experience....  More
27 days ago

Abu Dhabi 30-May-2017

Information Security Engineer
Source: Sofomation
Details: Microsoft Certified System Engineer (MCSE). Certified Information Systems Auditor (CISA). II Certified Information Systems Security Professional (CISSP)....  More
30+ days ago

Abu Dhabi 09-May-2017

Industrial Cyber Security Specialist (Information Technology & Telecom)
Source: Sumaco
Details: Microsoft Certified IT Professional (MCITP), Microsoft Certified Technology Specialist (MCTS) with strong knowledge in Industrial Control System Operating...  More
30+ days ago

Abu Dhabi 07-May-2017

PC Technician
Source: General Dynamics Information Technology
Details: Microsoft Certified IT Professional (MCITP):. Maintenance and troubleshooting support of information systems applications and related peripheral hardware....  More
27 days ago

Abu Dhabi 30-May-2017

Information Security Engineer (Compliance)
Source: Union Gulf Recruitment
Details: Microsoft Certified System Engineer (MCSE). Certified Information Systems Auditor (CISA). Certified Information Systems Security Professional (CISSP)....  More
30+ days ago

Abu Dhabi 23-May-2017

Senior Engineer-IT Systems
Source: Fuschia Careers
Details: Microsoft Certified Master (MCM):. Microsoft Certified Solutions Engineer (MCSE) within the following area:. Citrix Certified Associate - Virtualization CCA – V...  More
30+ days ago

UAE 19-May-2017

Information Assurance II
Source: General Dynamics Information Technology
Details: Information Technology Certification Requirements Microsoft Certified Solutions Expert (MCSE) – Microsoft Exchange/Windows Server or equivalent Cisco Certified...  More
30+ days ago

Abu Dhabi 05-April-2017

Industrial Cyber Security Specialist
Source: Star Services LLC
Details: Microsoft Certified IT Professional (MCITP), Microsoft Certified. Operating System Hardening, Microsoft Certified System Administrator (MCSA) with....  More
5 hours ago

Abu Dhabi 26-June-2017

Manager - Information Security
Source: Michael Page AE
Details: O Microsoft Certified Systems Engineer:. O CISM Certified Information Security Manager.  Security Architecture:....  More
30+ days ago

Dubai 14-April-2017

INDUSTRIAL CYBER SECURITY SPECIALIST
Source: SOS HR Solutions
Details: Microsoft Certified IT Professional (MCITP), Microsoft Certified. Operating System Hardening, Microsoft Certified System Administrator (MCSA) with experience in...  More
30+ days ago

UAE 08-May-2017

Idustrial Cyber Security Specialist
Source: SUNDUS Recruitment
Details: Microsoft Certified IT Professional (MCITP). Microsoft Certified System Administrator (MCSA) with experience in managing Industrial Control System Windows...  More
30+ days ago

UAE 21-April-2017

IT Support Supervisor Confidential Company
Source: dubizzle.com
Details: Certificate of Microsoft Certified System. Microsoft Certified Desktop Support Technician (MCDST). Certificate of Microsoft Certified Professional (MCP) is...  More
17 days ago

Dubai 09-June-2017

More
Source: Sofomation
Details: Microsoft Certified System Engineer (MCSE). Certified Information Systems Auditor (CISA). II Certified Information Systems Security Professional (CISSP)....  More
5 days ago

Abu Dhabi 21-June-2017

ADPE/Service Desk Admin - United Arab Emirates (Current US Secret Clearance Required)
Source: Akima, LLC
Details: Microsoft Certified Professional (MCP) is highly desired. Desktop computer, printer/copier, digital sender, telephones, Remedy 7.6, Microsoft Exchange Server...  More
26 days ago

Abu Dhabi 30-May-2017

Project Manager - Techno Functional - MS Dynamics
Source: Jerry Varghese
Details: Preferably should be a Microsoft certified professional, MBA in Finance and Accounting/Bachelor degree holder/B.Tech/Degree in Information technology....  More
26 days ago

UAE 30-May-2017

INDUSTRIAL CYBER SECURITY SPECIALIST
Source: SOS HR
Details: Microsoft Certified IT Professional (MCITP), Microsoft Certified. Operating System Hardening, Microsoft Certified System Administrator (MCSA) with experience in...  More
30+ days ago

UAE 07-May-2017

SharePoint Developer - MUST BE UAE BASED
Source: Michael Page AE
Details: Microsoft Certified Professional SharePoint Developer. Proficient use of Microsoft Office products and Adobe Photoshop....  More
30+ days ago

Dubai 23-May-2017

System Administrator
Source: Indeed
Details: A highly motivated, preferably a Microsoft certified professional, with minimum 5 years’ experience, to take over all aspects of networking, configuration,...  More
26 days ago

Dubai 31-May-2017

Integration Soft Engineer (Junior)
Source: Indeed
Details: Microsoft Certified Professional Developer. Integration Soft Engineer - Junior*....  More
15 days ago

Dubai 11-June-2017

Industrial Cyber Security Specialist
Source: Rawafed Services
Details: Microsoft Certified IT Professional (MCITP). Microsoft Certified System Administrator (MCSA) with experience in managing Industrial Control System Windows...  More
30+ days ago

Abu Dhabi 08-May-2017

INDUSTRIAL CYBER SECURITY SPECIALIST
Source: Indeed
Details: Microsoft Certified IT Professional (MCITP), Microsoft Certified Technology Specialist (MCTS) with strong knowledge in Industrial Control System Operating...  More
30+ days ago

Abu Dhabi 03-May-2017

INFORMATION SECURITY ENGINEER (COMPLIANCE)
Source: Indeed
Details: Microsoft Certified System Engineer (MCSE). Certified Information Systems Auditor (CISA). Certified Information Systems Security Professional (CISSP)....  More
30+ days ago

Abu Dhabi 17-April-2017

Step by Step Using Bootstrap3 with ASP.NET MVC5

What is Bootstrap?

Bootstrap is a well known and one of the most used collections of tools for web application that simplifies creating websites through it’s incredible built-in languages like Cascading Style Sheet (CSS),  HyperText Markup Language(HTML) as well as some optional JavaScript extensions.  It is used for icons, forms, typography,  buttons, tables, layout grids, and navigation. Bootstrap basically is a front-end open source framework having collection of tools that contains HTML and CSS-based design templates along with Javascript to create a responsive design for web applications. Bootstrap provides a base collection including layouts, base CSS, JavaScript widgets, customizable components and plugins.

A bit about Bootstrap History and Version Details

21st century is the century of relations in the field of information technology. Many tools are invented that has made this sector easy to learn and progress with a very little work. These tools are mostly free and open source which made them accessible by everyone. One of these tools is Bootstrap which brings a new platform to web developers. Bootstrap was developed by Mark Otto and Jacob Thornton and it is originally named as Twitter Blueprint because it is designed at Twitter.

Bootstrap has two major versions i.e. Bootstrap 2.3.2 and Bootstrap 3. Its version 3.0 provides a new philosophy i.e. mobile first which is a responsive web design and it can be used for computer monitor as well as mobile phones. Bootstrap is licensed by MIT and it is opened sourced by twitter on August 19, 2011 and can be easily downloaded from GitHub. Now recently Mark Otto Bootstrap 4 is in development stages and will be in market with new as well as modified form of tools. It has extraordinary features which makes it unique that is it is compatible with many latest versions of web browsers i.e. Google Chrome, Firefox, Internet Explorer, Opera, and Safari.

Nuget package commands allow ASP.NET users to easily install and use Bootstrap for designing web applications. JavaScript comes in this platform in the form of plugins i.e. jQuery which are supported on Modal, Dropdown, Scrollspy, Tab, Alert, Popover, Tooltip, Button, Typeahead, Carousel and Collapse.

Consider you are working as MVC Developer with WebDevTutorials. Our ASP.NET MVC application has a controller named EmployeeController. We want our EmployeeController to have a public non action method. What we will do to achieve this?

  • A. We can’t make a public method as non action in ASP.NET MVC.
  • B. Make return type void to a public method.
  • C. Add VoidAttribute attribute to a public method.
  • D. Add NonActionAttribute attribute to a public method.

For a complete online test and Practice Exams on Web Technologies, Click Here.

 Correct Answer: D

Let’s follow a step by step approach to learn integrating any Bootstrap theme with ASP.NET MVC Application, as we already have covered a little about it in another ASP.NET MVC Tutorial.

Using Bootstrap 3.0 with ASP.NET MVC 5

  1. Find any theme that you want to use for your website. In this article I am using Bootstrap Creative Theme. Follow the URL to find a theme for your website here (https://wrapbootstrap.com/?ref=StartBootstrap):
    ASP.NET MVC Bootstrap
  2. Check the live demo of creative theme which I will implement for ASP.NET MVC application.
    http://ironsummitmedia.github.io/startbootstrap-creative/
  3. Extract the downloaded folder you will get the files like this:Bootstrap with ASP.NET MVC 5
  4. Create the ASP.NET MVC Web Application Project in Visual Studio 2013.ASP.NET MVC in Visual Studio 2013
  5. Once you have created the ASP.NET MVC Project go to the folder where you have downloaded the theme.ASP.NET MVC 5 Bootstrap Theme
  6. Copy the folders related to CSS (Cascading Style Sheet) to this project in Content folder.Visual Studio 2013 CSS folder
  7. Similarly copy the JS folder and include this in the Script folder.Visual Studio 2013 JS Folder
  8. Now we need to create the views according to the template. Go to to the theme folder and open the index  page in browser. Our main web layout will be like this.ASP.NET MVC 5 Index Page
  9. Go to view’s shared folder and open _layout.cshtml and comment all the content in it.Views in ASP.NET MVC 5
  10. Open theme index file in notepad and copy the content and paste in _layout.cshtml page.Theme Index in ASP.NET MVC 5
    Exam 70-486
  11. Collapse the head and other sections in body as follows:Layout in Visual Studio 2013
  12. Remove header and sections which is highlighted from body tag we will use this for  index page and write @RenderBody().RenderBody in ASP.NET MVC
  13. Expand the head element and set the path of link and href with the path of our project and change href accordingly.ASP.NET MVC 5 Project
  14. Change the path accordingly with the jquery reference also and your layout page is ready now.jQuery Reference in Visual Studio 2013
  15. Now go to Views, home folder and open index.schtml file and delete all the content in it. Place the code header and sections which we remove from theme’s index file body element.ASP.NET MVC Index View
  16. Build the project and run. You will get the beautiful theme page for your ASP.NET MVC Web Application.Bootstrap with ASP.NET MVC 5

Conclusion:

So here we learn step by step how we can use any theme in Bootstraps to our ASP.NET MVC web application. And How we can set main layout page and index page. Now we can add more views accordingly.

Bootstrap is the world’s most popular mobile ready web development framework for HTML, CSS and JavaScript. Bootstrap is for you if you want to quickly build a super cool website which work across devices and browsers. It is easy to learn and super powerful.

Following are the section details of this online course:

  • Section 1: Getting Started With Bootstrap
  • Section 2: Photo App Sales Website
  • Section 3: Portfolio Resume Using SASS
  • Section 4: Social Network Template
  • Section 5: Agency Landing Page Using LESS
  • Section 6: Photo Gallery
  • Section 7: CMS Admin Template
  • Section 8: Web Hosting Company Website
  • Section 9: Ecommerce Template
  • Section 10: Business Bootstrap Theme
  • Section 11: Blog Website
  • Section 12: Course Summary

Learn Bootstrap by Example

More You Must Read about ASP.NET MVC & Related

How to Customize Profile Info in ASP.NET Identity?

A security requirement on internet is one of the prime needs now a day. There are millions of user active on social networking sites as well as there are also some businesses like banks and insurance companies which have continuously a security risk of data theft. A secure platform is needed which secure the user’s data which is most precious from rest of the things. Therefore it is an essential task for every web developer to secure the web applications and all the services from those who can misuse them.

Microsoft introduces ASP.NET Identity as a system to manage access in ASP.NET application on premises and also in the cloud.

ASP.NET Identity Framework is an open source platform and can be customized according to requirement. Through this platform it provides a user membership in the form of store or hybrid application which eradicates every security risk to web applications. Now every social networking site uses a user authentication and authorization.  ASP.NET Identity Framework 2.0 can be used with ASP.NET Web Forms, MVC, Web Pages, Web API, and SignalR.ASP.NET Identity

This platform provides the major security like Two Factor Authentication, Account Lockout, and Account Confirmation etc. Along with these features a more important feature which makes it more prominent is that supported by multiple storage systems like Relational Databases, SharePoint, Azure etc.

Here in this Web Development Tutorial, we will understand about the default profile details and learn how to customize Profile Information in ASP.NET Identity. Let’s follow step by step approach to customize profile information.

Exploring the Default

Create a New Project in Visual Studio 2013

Open Visual Studio 2013 and Create a new project from “File -> New Project”. Select ASP.NET Web Application. Type any name for the project as I am using “TestIdentity” and click OK.ASP.NET Web Application Project

Select MVC and make sure we have selected in Authentication to Individual User Accounts which is used for those applications that store their user profile information in SQL Server database as shown below. There are other authentication methods like using existing accounts for Twitter, Facebook, Microsoft or Gmail etc. but I am not going into detail for those.Authentication Type

A default ASP.NET MVC Web Application is created. We can check reference identity libraries that are already added to our solution under references.

References for ASP.NET Identity

Otherwise we can install Microsoft ASP.NET Identity using Nuget or Package Manager Console.

Looking into Default Profile/Register Page

First build the project and view the default profile page in browser. We can easily find Register.cshtml file under TestIdentity->Views->Account->[Register.cshtml]. Right click and select “View in Browser”. Default Register Page

We can see that, by default,  User Profile form has three fields i.e. Username, Password and Confirm password. So, in order to customize the profile, we are going to add more fields to Profile/Register form.

Note: You can download the source code for the project here. Kindly note that I have excluded the package folder from source code to reduce the size of file.

Customizing the User Profile using ASP.NET Identity

Step 1. Add Custom Properties in Application User Class

To add custom fields, we will go to Models folder and open IdentityModel.cs file. There are two classes inside this file as:

  • ApplicationUser – is the class where we will add other properties i.e. Email, Address and Phone Number.
  • ApplicationDbContext – used for connection to database as base constructor having “DefaultConnection” name same as we have in our Web.Config file.

Add Custom Properties

Step 2. Customize Register ViewModel

Build the project so that we can use these properties further. Now open AccountViewModel.cs file where we will find RegisterViewModel class that is used for Registration Form. Here we will add those three fields that I want to show in registration form. For these custom fields, we made the Email as Required field using Data Annotation technique. Similarly Display is also a Data Annotations that is used to display Name that we want rather than exact property name. I have already discussed in another ASP.NET Web API Tutorial about Data Annotation Technique.

Register ViewModel

Step 3. Register Form View

We need to change the Register form view. Go to views folder click account folder and here we will find a Register.cshtml. Add Email, Address, and phone using Html helpers [To understand more about HTML Helpers in MVC, click here.]as follows:Register FormView

Step 4. Account Controller

The last step is to change the Register Method in Account Controller. Go to controller folder and Click account controller. The Application user has other properties as well now here we will map the Email, Address and phone number from RegisterViewModel to Application user’s properties. The Usermanager.createAsync method is used to register the user and if the result succeeded the SignInAsync method is used to automatically login the user after registration.Update Account Controller

Step 5. View and Verify Results

Finally, build the project and view the Register.cshtml file again in browser as we did earlier and check the registration form that displays fields that we have just added.  Customized Profile

Now, if we fill the Fields and click register button, it will registered a new profile successfully and login as well.Authentication with ASP.NET Identity

In order to further validate the output, we can check the values in database. Open web.config file and check connection string.ASP.NET Identity Configuration

Go to server explorer and click data connection enter the Server name and find the database as we see in connection string in web.config file.ASP.NET Identity database

Check the tables that Identity is using. Right Click on Asp.net user and click Show Table Data.

ASPNetUser Data

The table is showing the information that we just added using Registration form.

User Registration
Concluding Remarks:

This is how we can customize Profile Information using ASP.NET Identity to increase security in our Application? and we can see how the changes are reflected in database table. We used only Individual User Accounts although there are other authentication methods where we use built-in email accounts like Facebook or Gmail account etc. that will be cover in next topic.

Download Source Code

More You Must Read about ASP.NET MVC & Related

Top New Features of C# 6.0

In previous post, we discussed and learnt about New Features of ASP.NET vNEXT. Here in this post, we will discuss the top new features and enhancements introduced in Microsoft C# 6.0. You can find a very good pocket reference for C# 6.0 here.

Before we dive deeper to discuss features of latest version of C#, let’s analyze how C# evolves and what key features introduced in all previous versions.New Features In C# 6.0

New Features in C# 6.0

Auto Property Initializer

This feature enables us to set the values of properties right at the place where they are declared. Previously, we use constructor to initialize the auto properties to non-default value but with this new feature in C# 6.0, it doesn’t require to initialize these properties with a constructor as shown below:Auto Property Initializer

Note: We can use the feature on getter/setter as well as getter only properties as demonstrated above. Using getter only helps to easily achieve immutability.

Exception Filters

Microsoft introduced this CLR feature in C# with version 6.0 but it was already available in Visual Basic and F#. In order to use Exception Filters in C#, we have to declare the filter condition in the same line as that of the catch block and the catch block will execute only if the condition is successfully met as shown below:Exception Filters in C# 6.0

The above code checks if the special exception occurred is of type SqlException. If not, the exception is taken care of.

Here is another case that shows how we can check the Message property of the exception and indicate a condition appropriately.Exception Filter in C# 6.0

Note: Remember that Exception Filter is a debugging feature rather than a coding feature. For a very nice and detailed discussion, please follow here.Exam 70-486

await in catch and finally block

We frequently log exceptions to a document or a database. Such operations are resource extensive and lengthy as we would need more time to perform I/O. In such circumstances, it would be awesome on the off chance that we can make asynchronous calls inside our exception blocks. We may additionally need to perform some cleanup operations in finally block which may also be resource extensive.

await in catch and finally

C# Unity Developer

Dictionary Initializer

As oppose to older way of initializing a dictionary, C# 6.0 introduces more cleaner way for dictionary
initialization as follows:Dictionary Initializer in C# 6.0

Previously same was done in following way:Dictionary Initializer older way

Important Note: Primary Constructor has been removed from C# 6.0. For more details, please follow here.


More Related

Top 10 Interview Questions and Answers Series:

Top New Features of ASP.NET vNext

Sinсе thе creation of.NET stage about 15 уеаrѕ аgо, in rеgаrdѕ tо hоw wе manufacture Wеb applications? ASP.NET vNеxt rесоnѕidеrѕ thе сеntеr system from thе bеginning with a more рrеѕеnt dау fеаturеѕ that givеѕ bеttеr execution, lоwеr аѕѕеt utilizаtiоn, аnd аn аѕуnс mоdеl for еnhаnсеd еxесutiоn, adaptability, аnd есоnоmу in cloud-based fасilitаting ѕituаtiоnѕ.ASP.NET vNext

ASP.NET vNеxt gives a mоrе secluded, extensible, and inсlinе ѕtruсturе for building Web applications:

The ѕоrtѕ оf applications wе construct tоdау аrе аltоgеthеr diffеrеnt frоm thе оnеѕ wе fаbriсаtеd аt thе timе ASP.NET wаѕ initially соnѕidеrеd. Today’s Web аррliсаtiоnѕ аrе mоrе dynamic and dереnd considerably lеѕѕ оn server-created HTML, Inѕtеаd, they utilizе riсh customer usefulness that dереndѕ оn аdminiѕtrаtiоnѕ to ассumulаtе dаtа.

Bасkеnd аррliсаtiоnѕ tоdау аrе frеquеntlу diѕѕеminаtеd аnd rерrеѕеntаtivе errands to application ѕеrvеrѕ tо оfflоаd dirесt рrераring from thе Wеb server itѕеlf. Indeed, even single-server HTML applications hаvе a tеndеnсу tо bе a great dеаl mоrе secluded and draw аѕѕеtѕ from numеrоuѕ assorted sources as орроѕеd tо building a ѕоlitаrу solid Web раgе in оnе ѕhоt, whiсh brings аbоut mоrе “talkative” Wеb application.

Sitе раgеѕ tоdау likewise hаvе a tеndеnсу tо bе mоrе straightforward ѕо as tо bolster cell рhоnеѕ that need tо lоаd rарidlу and fit оntо little ѕсrееnѕ. Tоdау’ѕ Wеb аррliсаtiоnѕ have a tеndеnсу tо be muсh chattier, and manage аll the mоrе, уеt littlеr, demands.

ASP.NET vNеxt givеѕ you a сhаnсе to pick between twо runtime mоdеѕ: Full CLR аnd thе light wеight Core CLR:

Likеlу thе most radical fеаturеѕ of ASP.NET vNеxt iѕ that it асquаintѕ twо рluggаblе application hаѕ with boot uр vNеxt aррliсаtiоnѕ. Tо begin with, there’s Full CLR runtime facilitating that bеginѕ uр thе full .NET 4.5 Frаmеwоrk runtimе аnd can еxрlоit аll thе соmроnеntѕ in thе full dеѕktор structure. Be thаt аѕ it mау, vNext аdditiоnаllу presents another Cоrе CLR thаt uses a сuѕtоm runtimе loader thаt rаiѕеѕ a lightweight vаriаnt of the Cоrе CLR runtimе.

The nеw application hоѕt runtime lоаdеrѕ аrе in сhаrgе of bootstrapping thе fitting KRE runtime either frоm an order linе host еxесutаblе оr from inside IIS with a loader that bооtѕtrарѕ from thе inside IIS рiреlinе.
Exam 70-486

Pаѕt the ѕtаrting bооtѕtrаррing, the Full CLR and Cоrе CLR offer thе ѕаmе KRE раrt eco-system, соnnесting tо parts frоm thе same NuGеt fееdѕ:

The Full CLR iѕ a gооd сhоiсе when initially playing with ASP.NET vNеxt because it’ѕ likеlу thаt уоu’ll need ассеѕѕ tо lеgасу components and fеаturеѕ that simply аrе not available уеt in vNеxt. Fоr example, if уоu wаnt to use an alternate database рrоvidеr likе MоngоDb tоdау, there’s no wау tо dо thаt уеt with thе Cоrе CLR. But with thе Full CLR, уоu can rеfеrеnсе the existing .NET 4.5 MоngоDb NuGеt расkаgе and gо tо town.

The drаwbасk of thе Full CLR iѕ thе аѕѕеt оvеrhеаd оf stacking uр the full .NET runtime соntrаѕtеd with the Cоrе CLR. In mу intrоduсtоrу tеѕtѕ соntrаѕting memory fооt ѕhареd imрrеѕѕiоnѕ, thе Full CLR iѕ running аlmоѕt dоublе thе mеmоrу fооt ѕhареd imрrеѕѕiоn аѕ thе Cоrе CLR. Thе Full CLR iѕ аdditiоnаllу fixеd tо Windows with its rеliаnсе оn the full .NET 4.5.x Framework аnd аnу xcopy ѕеnding will in аnу еvеnt rеԛuirе thе рrеѕеnсе оf .NET 4.5.x kеерing in mind thе end goal to run.

Top nоtсh NuGet Pасkаgеѕ:

Bоth аdарtаtiоnѕ of vNext import соnditiоnѕ through NuGet bundles inѕtеаd оf соngrеgаtiоnѕ. Nоtwithѕtаnding when you fаbriсаtе уоur оwn librаriеѕ, thеу саn bе distributed соnѕеquеntlу аѕ NuGet bundlеѕ when you mаnufасturе уоur lаѕt уiеld. Hоwеvеr оf соurѕе, referenced class librаriеѕ аnd applications dоn’t рrоduсе аggrеgаtеd уiеld, уеt rather соdе iѕ gаthеrеd аt runtimе into mеmоrу utilizing thе nеw ultra-quick Roslyn соmрilеr innоvаtiоn.

If you are really anxious to develop ASP.Net vNext applications, you should have Visual Studio 2015 installed. You can get information about Visual Studio 2015 edition here.


More You Must Read about ASP.NET & ASP.NET MVC & Related

Top 10 Interview Questions and Answers Series:

Interview with Rahul Sahay – “ASP.NET MVC Code First”

I am excited to introduce my guest today, Rahul Sahay, Owner of a very active Technological Facebook group “ASP.NET MVC Code First“, a decent blog and Author of following books:

  • Hands-On with ASP.NET MVC Covering MVC6
  • Building Single Page App with ASP.NET MVC5 and AngularJS

Blog My View (http://myview.rahulnivi.net) which is nearing 1.5 Lac visits. 70K visitors visit site on regular basis. Facebook group members count reaching 13,000. Congratulations on that Rahul :)
Imran: Rahul, I have given a short introduction about you, your blog and books. Please tell us more about you and what you do?

Rahul: Thanks for kind introduction. Frankly speaking, last year when I started writing my blog; I started on 1st Jan 2014; that was last year resolution to spread the word. Later on I realized that people started liking my articles as my articles basically focus on How To stuffs? rather writing high level stuffs.

Imran: When did you start your Facebook group “ASP.NET MVC Code First”, and why did you create it? What was the motivation or inspiration behind it?

Rahul: Again, that get started last year to engage more people from same field. It’s like collect all the fishes from different ponds and put them in a single pond to have more engaging and interactive discussion on Facebook group.

Imran: What do you feel makes your Facebook group special?

Rahul: Hmmm. That’s a typical question. However, still with Facebook group long way to go as there are couple of groups on the top of this. But, special thing about this, we encourage people to cascade Job opportunities as well so that freshers/experienced people at the end get benefited.

Imran: What are some of the hot topics that seem to always be discussed within the group?

Rahul: Off course, MVC is the key thing. But, I also encourage people to talk about other technologies as well like AngularJS, WCF (Windows Communication Foundation), Web API, Entity Framework, Azure, Other JS testing patterns like Jasmine, QUnit and many more stuffs which is really hot cake in the market.

Imran: For someone new to this group, how do they get the most out of it?

Rahul: He/She need to be active not all the times. But, whenever they login, once check the discussion tab there, so that they will come to know latest happenings on the group.

Imran: For our audience, please discuss in detail about the books you have written?

Rahul: I start in a descending order. So, the latest one which I have written is actually marriage of tons client/server technologies.
Here, I have used technologies like ASP.NET MVC which is basically base framework for the application.

  • Web API:- Off Course in order to data transportation; I found Web API being the best. Since, it embraces stateless design out of the box and built in HTTP verbs support the same.
  • AngularJS:-This is one of the most talked technology in the neighborhood today. I find, Angular JS is the most suitable one for building SPA (Single-Page Applications).
  • QUnit:- This one I have used for testing my Web APIs. QUnit is one of the most popular JavaScript libraries used by JQuery team to write their test cases.
  • Jasmine:- Again, Jasmine is a different JS testing library used for writing test cases for AngularJS. I have chosen this one as angular team also uses the same one to write their test cases.
  • Unit of Work Pattern:- I am fan of this design technique. It always gives me ability to aggregate the changes or keep the changes at one place and use at multiple place.
  • Factory Pattern:- Under the hood of UOW, I am using factory pattern for initializing the factors like dbContext, off course, for the 1st time and then in subsequent call, it will be addressed by the same instance until site is closed.
  • Solid Principles:- SRP is one of the most used technologies from Solid principle. I usually keep my dependencies per class basis. This also helps me in writing clean Unit test cases.
  • Chutzpah Project:- This one I installed from Extension and Updates as this helps to integrate JS Test cases under the hood of MS Test runner. So, what will happen as soon as you click run all?, This will run both managed test cases and un-managed test cases under the same hood.

I have also written book on MVC. That is Hands-on with ASP.NET MVC. This basically talks about MVC right from the scratch till professional level Implementation.

Imran: Please discuss about your blog. What major areas are focused and how a developer can take maximum benefit from it?

Rahul: Frankly speaking I have started the blog as in for my learning purpose means as a online repository which I can refer at any point of time. But, later on I realized that people are coming to my blog and reading my article and providing feedback for the same. This actually boosted my confidence and then I decided, OK I will go ahead and make this a regular blog which will talk not only about Microsoft Technologies but discuss latest trend in the market like Angular. Till date, I think I have written 163 articles. And in about 1 year response is very good.

Imran: It’s really amazing Rahul. What are your future plans about introducing more exciting things for your group members? Also, Is there any specific topic you are planning to write a book about?

Rahul: Exciting thing to me is always talk about latest technology and share the same with group members. it’s very important to have the implementation knowledge at least on these new technology. Web is changing rapidly. People now converging towards JS framework more rather than managed code environment like .Net or Java. So, in future I’ll be talking more on ASP.NET 5 which is again a great change in this area and then off course Angular and Typescript. Also, I would like to focus on Azure and its capabilities. Next book which is coming is on WCF.
It is basically enterprise edition. So, here readers will experience end to end experience right from the scratch. Again this book is very deep dive. I think people will love it.

Imran: Finally, What do you suggest all your group members and .Net developers at large to improve their skills?

Rahul: Learning is important and learning new skills, new improvements of existing language like C#, and implementing the same in your existing project will help any person to improve the skills. This is very important because these days even client is very demanding, they don’t want to invest or focus on old stuffs.

Imran: Thanks a lot Rahul. I really feel proud to have you with us and sharing your thoughts. Thanks once again.
Exam 70-486


More You Must Read about ASP.NET MVC & Related

Top 10 Interview Questions and Answers Series:

Custom Authentication and Authorization in ASP.NET MVC

ASP.NET MVC provides us the basic Authorization and Authentication functionalities when we use the Project template as Internet. It does all the major functionalities such as Role membership management, Login credential validation handling etc. For more information about basic authorization in MVC application check out here our article “Insight of ASP.NET MVC’s Authorize Attribute”.
In brief we can just restrict the anonymous users by decorating our Controllers and Action Methods using the Attribute called Authorize. This will redirects the Anonymous users to the login page and with some overriding we can navigate them to the Custom Error page as well. But it’s not flexible enough if we are going for more Enterprise level application where the security matters.

So there comes our concept of Customizing the Authorization and Authentication in ASP.NET MVC, let’s play around with it for some time.

Custom Membership provider in ASP.NET MVC

MVC provides us few .NET built in Membership providers where implementing that and consuming is quite easy but as discussed earlier it doesn’t provide enough flexibility in enhancing our security. The other option is to implement the own providers.

You would have noticed while implementing the Default membership provided by .NET, a table created with Schema related to Authentication and Authorization and persist the credentials that the end user creates. This work around is done automatically, but in case of Custom Authentication it needs to be created starting from Scratch or can use the existing Schema system of already built in Application.

Setting Up the Database

  • If you have the Security database configured already then you can skip the step, else let us create ASP.NET security database.
  • Open Visual Studio command prompt and type in the command “aspnet_regsql”.Visual Studio Command Prompt
  • Which pops up a Sql wizard, click on the Next.ASP.NET SQL Server Setup Wizard
  • You can decide here, whether to move on with existing on or replace the security database.ASP.NET Membership
  • Provide you Server name and Database, the wizard will automatically load it with ASPNET security schema loaded table.ASP.NET MVC MembershipCustom Membership Provider

Creating Custom Membership

  • Open up Visual studio 2012 or Later and create a Class library project.ASP.NET MVC Custom Membership
  • Now it’s time to refer an assembly called System.Web.ApplicationServices. This namespace provides us different classes that enables us to access the Forms authentication, Roles and Profiles application services. To refer assembly, Right click on the Reference folder, then Add reference and Select Assemblies. Search or Scroll for corresponding namespace mentioned earlier and add it.Forms Authentication, Roles and Profiles
  • Create your custom Authentication class here for instance its WebDevelopmentCustomAuth and derive it from the MembershipProvider class.Custom Authorization
  • MembershipProvider provides us a method called “ValidateUser()” which is one that needs to be overridden.Membership Provider

Implementing Custom Authentication into ASP.NET MVC4 Client

  • Create a brand new ASP.NET MVC 4 application (The template project could be Internet).
  • We can replace or add some membership tags in our Web.Config file mapping to our Custom Authentication Class library.
  • Now decorate the required Controllers or ActionMethods with Authorize attribute as usual.Authorize attribute in ASP.NET MVC
  • It’s important that we need to set Off the Simple Membership and Auto Form authentication in the Web Config file.
    <add key= “enableSimpleMembership” value= “false” />
    <add key= “autoFormsAuthentication” value= “false” />
  • Now Run the application by hitting F5 and navigate to the Authorize attribute decorated Action Method.ASP.NET MVC Action Method
  • You will be navigated to the Login page as desired.

Customizing Authorization (Role Provider)

  • In our before Class library project, create a class CustomRoleProvider that inherits the RoleProvider class.
  • Where the RoleProvider class provides us with the method for handling the Roles, called as GetRoleForUser().
  • We can override that particular function with our logic.
  • Now in our MVC 4 client project that we created earlier, open up the Web.Config file and add or replace the RoleManager Section as below.
  • Then decorate the ActionMethod’s Authorize attribute with the property called Roles.
  • If we again run our application and navigate to decorated ActionMethod then you can see the login only if your username has the role Administrator.

We can also make use of Third party Authentications such as Google, Microsoft, Facebook etc. This can be implemented by deriving our WebDevelopmentCustomAuth class from ExtendedMembershipProvider class, where this particular class has its base class as MembershipProvider class. We also need to refer an assembly called as WebMatrix.WebData and can manipulate the AccountController to make use of other Social type of Authentication.MVC Third Party Auth

Custom Authorization and Authentication provides us enough flexibility in implementing Security, it’s quite a wide topic. I’ve written the most prominent way of implementing it and I hope this helps you in learning Customization and can move forward in securing your application.

Thanks for reading, make your app Non-Screwable !

More You Must Read about ASP.NET MVC & Related

ASP.NET MVC Scaffolding

Computer programming is getting smarter & smarter and the same way it’s been shrinking & layman readable. Let’s go to the first era of Computer science where the real geeks sit and code tons of lines for months just for moving an object on screen or for fetching an employee record from the database. But now the things are different; WE (Programmers/Developers) think it’s silly! Aren’t we?

Scaffolding engine uses Microsoft’s T4 templates to generate basic controllers and views for the models.
Scaffolding blends with Entity framework and creates us the instance for the mapped entity model and writes down CRUD Operations code for us. That’s really charming and time saving that enhances developer’s productivity. Let’s get into real implementation action for some time.
I’m going to use Visual Studio 2012 express and ASP.NET MVC 4.

Although when this ASP.NET MVC Tutorial was written, we used Visual Studio 2012 Express with with ASP.NET MVC 4 but Scaffolding concept is same if you are using new versions of tools and frameworks like Visual Studio 2013 | Visual Studio 2015 with ASP.NET MVC 5.

Microsoft always involved in creating things simple yet powerful. Starting from vanishing old black screen till Drag & Drop application development IDEs.ASP.NET MVC Scaffolding
I do remember one of the Bill Gate’s quote

I choose a lazy person to do a hard job. Because a lazy person will find an easy way to do it.

Ok enough stories, let me come to the point, so Microsoft again comes with a powerful feature called Scaffolding in the world of ASP.NET MVC programming.

Huge time saver for ASP.NET MVC developers

Scaffolding engine for ASP.NET MVC models helps web developers in relieving him from the tedious & mundane task of writing CRUD Operations codes. That is, connecting to a database table and perform often doing task such as Create, Retrieve, Update and Delete records.

Scaffolding engine uses Microsoft’s T4 templates to generate basic controllers and views for the models. Scaffolding blends with Entity framework and creates us the instance for the mapped entity model and writes down CRUD Operations code for us. That’s really charming and time saving that enhances developer’s productivity. Let’s get into real implementation action for some time. I’m going to use Visual Studio 2012 express and ASP.NET MVC 4.

Setting up the Platform

As a prerequisites, I do consider that you might know how to create a database and table using Entity framework. If no, please go through this well narrated tutorial (Creating First application with Entity framework) and come back.

  • Open up Visual studio 2012 or later and create an ASP.NET MVC 4 application.ASP.NET MVC Application
  • Make sure we do have Entity Framework 5.0 or above in our project, which is automatically pulled in when you chose Basic while creating MVC new project. You don’t need to worry about if Entity Framework is not there. Nuget package console will help us getting it. You just need to type the command as marked in below figure and it will start the installation.Install-Package Entity Framework
  • Let us create a sample database/dbcontext using EntityFramework’s Code-First approach. We will create a Model class first as you can see the BookModel.cs in below figure.Model in ASP.NET MVC
  • Create a new class called “BookDbContext” which inherits DbContext class and create DbSet property so that our EF will recognize that as an Entity. Please note the naming convention, here we have used plural for class Book.DbContext Class
  • Now the next important thing is to Build our Project and make sure it compiles without an error, since only if the project gets built the Models will be instantiated and will be available for further reference.
    Note: Microsoft Exam on ASP.NET MVC normally has lots of questions regarding CRUD Operations, so understanding the Scaffolding Engine code is really helpful.
  • Create a new controller called “BookController”, wizard shows you the option called “Scaffolding options” here comes the magic. It asks you for
    • Template: Choose “MVC with read/write actions and views, using Entity Framework” as template. It will do the magic of creating code for all CRUD Operations/Actions and Views automatically.
    • Model class: Entity needs to be mapped to a specific model class, here in our case, it’s BookModel.
    • Data context class: Choose the DbContext class where the Book model is been referred and click on “Add”.Add ASP.NET MVC Controller
  • You can see the “BookController” is auto populated with DbContext instantiation and basic Action Results. For example, Index() action which returns a View where it injects a list of Books fetched from the Entity Framework Database. If you look at code inside Index() method that fetches the list, it’s pretty simple and only one line.BookController in ASP.NET MVC
  • Scaffolding engine also creates us four major views required for CRUD such as show in the below image. For instance the view Create.cshtml generates codes such as referring to the model
    @model WebDevelopmentHelp.Models.BookModel
    And creates an html form and fields using Razor’s Html Helpers.MVC Controllers
  • Alright, once we launch our application, we get 404 page since we don’t have Default/Index controller. Try post fixing the /book with the URL. As our DB is empty, an Empty Index view gets loaded.Index View in MVC Application
  • Let go ahead and create a Book entry by clicking on the Create New link and filling the form.Create New Record in MVC
  • Once the information on the form is submitted it will again be redirected to Index view by listing out the book information.ASP.NET MVC View List

Note: Scaffolding only creates us the basic functionalities and we couldn’t rely completely on that alone. It helps in igniting the basic setup and we can enhance further to attain the full featured functionality.

Hope this article helps you learning what is Scaffolding in ASP.NET MVC and kindly let me know if you have question!

  • Learn ASP NET MVC 5 step by step [Maruti Makwana, Corporate Trainer] 28 Lectures, 2.5 Hours Video, Intermediate Level
    Very easy to learn video series on Asp.Net MVC 5 Specially for those who are familiar with Asp.Net Web forms.
  • AngularJS for ASP.NET MVC Developers [Brett Romero] 10 Lectures, 1 hour video, Intermediate Level
    The Fastest Way For .NET Developers To Add AngularJS To Their Resume
  • ASP.NET with Entity Framework from Scratch
    [Manzoor Ahmad, MCPD | MCT] 77 Lectures, 10 hour video, All Level
    Latest approach of web application development
  • Comprehensive ASP.NET MVC [3D BUZZ] 34 lectures, 14 Hours Video, All Levels
    From zero knowledge of ASP.NET to deploying a complete project to production.

More ASP.NET MVC and Entity Framework related Tutorials:

Top 10 Interview Questions and Answers Series:

Understanding ASP.NET MVC Application Life Cycle

How ASP.NET MVC application works when the moment we type in the URL in browser and shoot a request? Let’s discuss the Life cycle of ASP.NET MVC application.

A developer must understand the life cycle of ASP.NET MVC so that he gain a full control over the developer platform. First let us see briefly, how the traditional ASP.NET application works. When the user sends a request to IIS, it validates the requested file extension & creates an application domain where the app can run. Later HttpApplication object is created once after all the HTTP object such as HttpContext, HttpRequest and HttpResponse are created. Then the request is processed by the two prominent pillars called HttpModule and HttpHandlers.

Hope that would be a brushup on legacy technique. Now let’s see the Life Cycle of MVC (Model View Controller) in detail.

ASP.NET MVC Life Cycle in Eagle’s view

When the user sends from the browser, it’s been handled by Routing concept and which navigates it to the appropriate Controller where controller picks up the relevant View and send it as a response to the User. The below diagram shows you the high level view of how the ASP.NET MVC processes a request.ASP.NET MVC Application Life Cycle

The first point should be noted in ASP.NET WebForms and ASP.NET MVC difference is that in MVC we don’t have the Page concept (In order to understand the difference between WebForms and MVC in details, follow here), whereas in Legacy we do have pages like .aspx, ashx etc. So if your question is, Then how does the requests are been pointed to in MVC? The answer, Is via Controllers. This special class is responsible for generating the response and sending the data back to the client.
For instance, the URL

http://www.webdevelopmenthelp.net/Book/Create

Says that it is requesting for the Controller class name “Book” and the Action Method name called “Create”.

Note: A Controller class can contain numerous Action Methods, if it needs to be accessed then it should be a public method.

ASP.NET MVC File Structure

Global.asax file is responsible for handling the Application and Session level events involved in ASP.NET MVC life cycle. IIS runs this as the first file when the request comes in. Let us look at the project and how the files been structured.

Global.asax in ASP.NET MVC
As you can see in the above image that we have a Global.asax and a Folder called “App_Start” which holds four different files such as BundleConfig, FilterConfig, RouteConfig and WebApiConfig. These play a very prominent role in deciding the Application’s control and flow.

Consider you are working as MVC Developer with WebDevTutorials. Our ASP.NET MVC application has a controller named EmployeeController. We want our EmployeeController to have a public non action method. What we will do to achieve this?

  • A. We can’t make a public method as non action in ASP.NET MVC.
  • B. Make return type void to a public method.
  • C. Add NonActionAttribute attribute to a public method.
  • D. Add VoidAttribute attribute to a public method.

For a complete FREE online test and MCSD Practice Exams on Web Technologies, Click Here.

 Correct Answer: C

Global.asax

Now let’s see deep into Global.asax file,ASP.NET MVC Global.asax
As you can see the Class is been inherited from System.Web.HttpApplication. As we know that we can handle the Application level events with the help of Global.asax even from the traditional ASP.NET it works as the same. Lets have a quick brush-up regarding those events.

  • Application_Start() – Triggers when the application starts for the first time
  • Application_Init() – Triggers when the application initialize for the first time
  • Application_BeginRequest() – Triggers each time a new request comes in
  • Application_EndRequest() – Triggers when request ends
  • Application_AuthenticateRequest() – Triggers when the request is to be authenticated
  • Application_Error() – Triggers when an application level error occurs
  • Application_End() – Triggers when the application times out or ended
  • Session_Start() – Triggers when there a user session starts
  • Session_End() – Triggers when the user’s session is ended

Here in sample ASP.NET MVC, we can see that Classes under App_Start folder is been invoked by passing necessary parameters.

Routing Module

RouteConfig is the most prominent Class involved in our Application life cycle’s first step, i.e handling the routes. UrlRouting Module is been informed about these Routes with the help of method called MapRoute().Register Routes in ASP.NET MVC

So basically what happens when the request comes in is, the RouteConfig find the matching route format from top and present that to RouteTable where it maps to the appropriate Controller.

Note: Route matching first will be taken in the RouteConfig file.

Controller Factory

The next vital step in MVC application life cycle is Controller factory, where if this factory receives the appropriate request from the RouteHandler, it generates the responding Controllers for the request. ControllerFactory creates the Controller Object and it implements the IControllerFactory interface.

When the mapping Controller object is created it comes to User defined Controller Class, for instance here we have the Book Controller class as a sample.Controller in ASP.NET MVC

Please note that, the BookController class implements Controller.Exam 70-486

Action Invoker in ASP.NET MVC Framework

The next important thing after creating Controller object is to, pick up the right ActionMethod based on the request parameter. ActionInvoker class is responsible for finding the method and invoke it.

ActionInvoker class implements the IActionInteface where we do have a method called InvokeAction.

Below screenshot represents some ActionMethods of the BookController class.ASP.NET MVC Action Invoker

  • Learn ASP NET MVC 5 step by step [Maruti Makwana, Corporate Trainer] 28 Lectures, 2.5 Hours Video, Intermediate Level
    Very easy to learn video series on Asp.Net MVC 5 Specially for those who are familiar with Asp.Net Web forms.
  • AngularJS for ASP.NET MVC Developers [Brett Romero] 10 Lectures, 1 hour video, Intermediate Level
    The Fastest Way For .NET Developers To Add AngularJS To Their Resume
  • ASP.NET with Entity Framework from Scratch
    [Manzoor Ahmad, MCPD | MCT] 77 Lectures, 10 hour video, All Level
    Latest approach of web application development
  • Comprehensive ASP.NET MVC [3D BUZZ] 34 lectures, 14 Hours Video, All Levels
    From zero knowledge of ASP.NET to deploying a complete project to production.

Action Result

As we are clear that, once the ActionMethod executes our logic we will return an ActionResult, based on the type of Result it returns, View generates accordingly.

Before that we do have some ActionFilter methods which is invoked based on ActionMethod’s life cycle. Some methods are such as OnActionExecuting, OnActionExecuted etc.

Let us see some of the ActionResult types as well,

  • ViewResult : Returns a view (html type page)
  • RedirectResult : Redirects to another action method
  • ContentResult : Returns Content (user defined)
  • JsonResult : Returns a serialized JSON data

View Renderer

The final and tangible step in MVC life cycle is rendering the View, where the user can see what he requested and get as a response. The ViewResult one of the ActionResult generates the appropriate View to the user, by parsing the Razor syntax (cshtml) and server side codes into HTML page to the Client.

ViewResult implements the IViewEngine Interface and has some view manipulating methods such as:

  • ReleaseView : To release the View
  • FindView : Maps the appropriate View
  • FindPartialView : Returns a Partial View

ASP.NET MVC Tutorial
We saw the internal workings of ASP.NET MVC application and how the control flows from IIS to View engine. Hope  his article helps you understand the Life cycle of MVC, kindly let us know if you have any questions.

Happy ASP.NET MVC Coding!

Advanced Web Developer Interview Questions and Answers Series: