New Features in MVC 5

In this article I am trying to give details of major MVC 5 features over MVC 4 in short.  
1. Bootstrap
                Now MVC project templates has been updated to use Bootstrap to give responsive look and feel which can be easily customize.

2. Authentication Filters
This are a new kind of filter, that run prior to authorization filters in the ASP.NET MVC pipeline and allow you to specify authentication logic for action, controller, or globally for all controllers. 

3. Filter overrides
                Override filters specify a set of filter types that should not be run for a given scope (action or controller). When we apply this attributes to action/controller then it has been excluded from filter, we have following filter overrides,
·         OverrideActionFiltersAttribute
·         OverrideAuthenticationAttribute 
·         OverrideAuthorizationAttribute 
·         OverrideExceptionAttribute  

Example:-
                 [OverrideAuthentication]
        public ActionResult Login(long? OrgId = null)
        {
            try
            {
                return View("Login");
            }
            catch (Exception)
            {
                throw;
            }
        }
               
4. Attribute routing
Using attribute based routing we can define the route in the same place where action method is defined. Following is an example of a route defined using the Route attribute. 
Example:-
              [Route("Account/ValidateUser/{UserName?}")]
        public ActionResult GetUsersDetails(int? id)
               {
            //Code Logic Here
        }

To enable attribute based routing we need to add following code in RouteConfig file
        public static void RegisterRoutes(RouteCollection routes)
         {
            routes.MapMvcAttributeRoutes();
  }
So now as we have attached the Route attribute to our action method our action method will be able to handle the requests which matches the URL pattern defined by the Route attribute.
Route Prefix:-If we have multiple action methods in a controller all using the same prefix we can use RoutePrefix attribute on the controller instead of putting that prefix on every action method.
Like we can attach the following attribute on the controller, [RoutePrefix("ControllerName")]
So now our Route attribute on our action method does not need to specify the common prefix, [Route("ActionName/{id}")]

5. ASP.NET Identity
The MVC project templates have been updated to use ASP.NET Identity for authentication and identity management.  Using third party authentication providers the task of authenticating the users can be delegated to a third party site such as google, Facebook. There are numerous sites that supports openID protocol such as google. With MVC 5 we can use it as part of a newly created project.  
To use this feature in your project, you need to go Startup.Auth.cs file which is in App_Start folder and enable to use another service by going to the ConfigureAuth method in Startup.Auth file.

6. Other Features:-
                There are few other features as well, basically its update in Visual studio templates, look and feel.
·         New Web Project Experience
·         ASP.NET Scaffolding Templates




Comments