Tuesday, 5 February 2013

ASP.NET MVC v ASP.NET

Having used ASP.NET MVC since it was in Beta in 2008, I am asked every time I mention those extra three letters why you'd bother moving a mature ASP.NET application to the new framework.

ASP.NET MVC is a framework that helps you build applications (note: I did not say web applications only) in a Model View Controller pattern. It breaks your applications presentation layer in to three distinct parts: The Model is the data. The View is the presentation. The Controller is the glue that holds it all together and manages interactions.

Traditional ASP.NET Application Architecture

In a classic ASP.NET application, the application logic is presented up to consuming applications through an ASP.NET container that returns web pages. If you want to access that logic through another consuming application that isn't web based then you implement web services that allow API access to that functionality. This is what you'd do to allow Javascript calls from your web application that didn't want to go through full ASP.NET page lifecycles to get standard HTML page data. Getting a JSON response is usual for an AJAX type call.



ASP.NET MVC Application Architecture

With ASP.NET MVC, one fundamental thing has changed. The ASP.NET application takes an HTTP Request and returns an HTTP Response of any type. That means that it can return HTML+CSS+Javascript to a browser if that is what it asks for or JSON or XML or any data format you want. It is just a generic HTTP response.

What this means is that you no longer have to build separate web services to expose application logic to consuming applications that do not want standard HTML. Those applications instead make requests and the ASP.NET MVC application is extended to process those requests and return whatever is required. The consuming application can be Windows-based, a mobile application, another web service or pretty much anything you can imagine.


There are a lot more differences between ASP.NET and ASP.NET MVC but this is an architectural one that will save you a lot of implementation time. Instead of wasting time on software infrastructure and scaffolding, you concentrate on writing business logic and exposing that business logic in consumable ways.

It is totally worth considering if you are have a greenfield project or are moving to later versions of .NET and are reconsidering ASP.NET.

1 comment: