2.27.2014

Difference between ASP.NET MVC 3 and ASP.NET MVC 4


S.No
ASP.NET MVC 3
ASP.NET MVC 4
1 Whether Bundling and Minification feature is supported in ASP.NET MVC 3?
No
Whether Bundling and Minification feature is supported in ASP.NET MVC 4?
Yes

What is Bundling and Minification?Why they are important?

It reduces number of HTTP requests that a web page needs to make. Bundling and Minification combines individual files into single, bundled file for scripts and CSS and then reduce the overall size by minifying the contents of the bundle.
2 Whether Display Modes feature is supported in ASP.NET MVC 3?
No
Whether Display Modes feature is supported in ASP.NET MVC 4?
Yes

What are Display Modes?

Display Modes is new feature provided in ASP.NET MVC 4. It lets an application select views depending on the browser which is making request. For example, if a desktop browser requests home page of an application it will return Views\Home\Index.cshtml view and if a mobile browser requests home page it will return Views\Home\Index.mobile.cshtml view.

3 Empty MVC Project template in ASP.NET MVC 3:
The ASP.NET MVC 3 Empty project template is not really empty. It contains css and js files.
Empty MVC Project template in ASP.NET MVC 4:
The ASP.NET MVC 4 Empty project template is really empty. It does not contain any css and js files.
4 Custom Controllers in ASP.NET MVC 3:
In ASP.NET MVC 3 we can only place custom controllers inside the Controllers folder.
Custom Controllers in ASP.NET MVC 4:
In ASP.NET MVC 4 we can place custom controller to custom locations.
5 Whether WebSockets and SignalR features are supported in ASP.NET MVC 3?
No
Whether WebSockets and SignalR features are supported in ASP.NET MVC 4?
Yes


What are WebSockets and SignalR?


ASP.NET MVC 4 supports WebSockets along with the new open source framework SignalR which allows to set up real time multi-user communication through open TCP sockets.
6 Whether Recipe feature is supported in ASP.NET MVC 3?
No
Whether Recipe feature is supported in ASP.NET MVC 4?
Yes

What are Recipes and provide their significance?
In technical language ASP.NET MVC 4 recipe is nothing but a dialog box that is delivered via NuGet with associated UI and code used to automate specific task. It’s like GUI for NuGet Package Manager. Recipes are set of assemblies which are loaded dynamically by Managed Extensibility Framework (MEF). MEF provides plugin model for applications. The main use of recipes are to automate development task, tasks that are encapsulated into recipes and used over and over again. For example, adding ajax grid to view or manipulating multiple areas of the application can be automated using ASP.NET MVC 4 recipes.
7 Is it possible to provide authentication using popular sites like Facebook or twitter into the web application using ASP.NET MVC 3?
No
Is it possible to provide authentication using popular sites like Facebook or twitter into the web application using ASP.NET MVC 4?
Yes

How it can be done?


Using DotNetOpenAuth library we can provide authentication using OAuth or OpenID providers. In ASP.NET MVC 4 Internet project template includes this library.
8 Whether Mobile Project Template is available in ASP.NET MVC 3?
No

Whether Mobile Project Template is available in ASP.NET MVC 4?
Yes

Why separate mobile project template while you can render your web application in mobile without additional customization?
The mobile project template touch-optimized UI using jQuery.Mobile.MVC NuGet Package for smart phones and tablets.

9 Asynchronous controller implementation in ASP.NET MVC 3?
In ASP.NET MVC 3, to implement asynchronous controller/methods we need to derive controller from AsyncController rather than from plain Controller class. We need to create two action methods rather than one. Fist with suffix “Async” keyword and second with “Completed” suffix. The method which initiated asynchronous process must end with “Async” and the method which is invoked when the asynchronous process finishes must end with “Completed”.

Example:

Please look at the bottom of the table
Asynchronous controller implementation in ASP.NET MVC 4?
The ASP.NET MVC 4 Controller class in combination .NET 4.5 enables us to write asynchronous action methods that return an object of type Task. The .NET Framework 4 introduced an asynchronous programming concept referred to as a Task and ASP.NET MVC 4 supports Task. The .NET Framework 4.5 builds on this asynchronous support with the await and async keywords that make working with Task objects much less complex than previous asynchronous approaches. The await keyword is syntactical shorthand for indicating that a piece of code should asynchronously wait on some other piece of code. The async keyword represents a hint that we can use to mark methods as task-based asynchronous methods. To implement asynchronous action method in ASP.NET MVC 4 we do no need to derive our controller class from AsyncController, async and await in cooperation with Task will do the magic. To mark the action method asynchronous use async in method signature. To wait for the other method to finish use await and to call multiple parallel methods use Task. The asynchronous method will return Task instead of plain ActionResult.

Example:

Please look at the bottom of the table
10 Enhancement in Default Project Template:
Not Applicable
Enhancement in Default Project Template:
The enhanced default project template is modern-looking. Along with cosmetic enhancements, it also employs adaptive rendering to look nice in both desktop and mobile browsers without need of any kind of additional customization.
11 Whether ASP.NET Web API is available in ASP.NET MVC 3?
No
Whether ASP.NET Web API is available in ASP.NET MVC 4?
Yes

What is ASP.NET Web API?
ASP.NET MVC 4 includes ASP.NET Web API, a new framework for creating HTTP services that can reach a broad range of clients including browsers and mobile devices. ASP.NET Web API is also an ideal platform for building RESTful services.
12 Whether Windows Azure feature is supported in ASP.NET MVC 3?
No
Whether Windows Azure feature is supported in ASP.NET MVC 4?
Yes

It supports Windows Azure SDK1.6 and new releases.

What is Windows Azure?
Windows Azure is an open and flexible cloud platform that serves as the development, data storing, service hosting and service management environment. Windows Azure provides developers with on-demand compute and storage to host, scale, and manage web applications on the internet through Microsoft data-centers.

Example for Asynchronous controller implementation in ASP.NET MVC 3 :
Example for Asynchronous controller implementation in ASP.NET MVC 4 :

Here the await keyword does not block the thread execution until the task is complete. It signs up the rest of the method as a callback on the task, and immediately returns. When the awaited task eventually completes, it will invoke that callback and thus resume the execution of the method right where it left off.

2 comments: