ASP.NET MVC is Microsoft’s latest web application development technology based on the principle of the separation of concerns. MVC stands for Models, Views and Controllers, respectively. Prior to MVC pattern, Web Forms was the prime Microsoft technology for web application development. However, Web Forms lacked flexibility of development and loose coupling. MVC addressed these concerns. This article presents brief overview of the top three features offered by ASP.NET MVC 5, which is the 5th version of the Microsoft MVC technology.

  1. Attribute Routing

The major difference in ASP.NET MVC and ASP.NET web forms is the way incoming requests are handled.

In Web Forms, incoming requests map to a file or resource on the web server. For instance, the requested URL can be of the form www.abcd.com/xyz.aspx. Here, the URL refers to an ASP.NET Web Form named xyz.aspx, located at the root directory. There is a one-to-one mapping between the URL and the page that is accessed, which must physically reside on the server.

On the other hand, MVC routing pattern maps URLs with action methods, resulting in cleaner and more SEO-friendly URLs (for instance, www.abcd.com/xyz/buy). This URL refers to the action method “buy” of the controller “xyz” on the domain “abcd”.

To see where these routes are configured, go to the solution explorer of your ASP.NET MVC application and find App_Start folder and find the RouteConfig.cs file. It contains a method named RegisterRoutes which takes a collection of type RouteCollection as a parameter. Inside this method are routes that are to be ignored; routes that are to be added can be defined. This is shown in the following code snippet:

public static void RegisterRoutes(RouteCollection routes){   routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”);    routes.MapRoute(      name: “Default”,      url: “{controller}/{action}/{id}”,      defaults: new { controller = “Home”, action = “Index”, id = UrlParameter.Option }      );}

Apart from defining routes in the RouteConfig.cs file, ASP.NET MVC 5 has introduced a new feature known as attribute routing which allows developers to specify a route as an attribute of the action method. To enable attribute based routing, you need to modify the RegisterRoutes method of RouteConfig.cs file as follows:

public static void RegisterRoutes(RouteCollection routes){     routes.MapMvcAttributeRoutes();}

To add a route on any action method, you simple have to add an attribute named Route and pass the route as parameter to it. For instance:

[Route(“Products/Sports/{id}”)]   public ActionResult GetSportsItems(string id){      ViewBag.Id = id;      return View();   }

  1. Default MVC Template replaced by Bootstrap

ASP.NET MVC 5 replaced the default MVC template with a much more flexible and standardize CSS library called Bootstrap. With the integration of Bootstrap in MVC 5, developers have got myriad of styling options right out of the box.

  1. Improved Identity Management and third party Authentications

ASP.NET MVC 5 has introduced a more robust, secure, and at the same time, flexible identity management mechanism. Now with MVC 5, developers need not to explicitly manage identity and authentication of the application users. Rather, these features come built-in with the framework and can be easily tweaked to achieve the desired identity and authentication operations. Also, MVC 5 provides authentication and logic features via third party applications such as Facebook, Google and Twitter, all of them right out of the box.