Its been a while since I blogged, but I am back with some new series coming through, mainly focusing on MVC and JQuery.
This small blog post is out to answer some of the common questions which I do see most often – “Differences between ASP.Net and ASP.Net MVC”, “Why ASP.Net MVC?” etc. Out of my experience I am listing out some of the important points around MVC in conjunction with ASP.Net Webforms.
With no doubt, I can assure you guys that ASP.Net Webforms served (and still serving) us in solving many complicated business problems through its huge and intensive components (especially .Net Framework Components). At this junction we need to remember that this extensive capability of ASP.Net is built on top of hiding Webs Statelessness and Html (which is not known very well at the time of ASP.Net’s birth), which unfortunately cost performance in some typical areas as listed below –
1. ViewState – On the first hand please read about ViewState in Dave Reed’s Post. This mechanism of maintaining state across Postbacks make the page size hefty and results in poor user experience with lot of data transferring in and out between client and server.
3. Testability – Automated UI Testing is a hard process for testers, due to ever changing IDs of Html and improper layouts rendered. Also Unit testing is a complicated task to Developers due to ASP.Net tightly coupled CodeBehind and its Markup.
4. Page Life Cycle – Every Request in ASP.Net needs to go through a structure life cycle which is complicated to achieve for many custom behaviors. Sometimes because of this cycle, we have to do something which are not best practices.
5. Code Separation – With CodeBehind model, we can achieve code separation between different UI and Business logic, but not up to the mark. It is hard to get separation to its maximum bar.
6. Leaky Abstraction – ASP.Net hides a lot of things, especially HTTP communication and Html from developers which can be crucial risks for custom behaviors. Some times we might end up without the knowledge of what’s going on with the process and might end up in reverse engineering the the problem to get to its root.
Above mentioned are some of the common areas where we might start falling apart with Webforms, but the beauty of ASP.Net comes with its maturity from 2002. Microsoft continuously making ASP.Net Webforms evolving and a simple example would be its ASP.Net 4.5 with Async Handlers and Modules.
Now lets start with ASP.Net MVC, with evolving Web technologies and especially Web 2.0 which mostly focused on REST – resource based utilization and Agile methodologies, Microsoft announced about its MVC in 2007 ALT.NET Conference. MVC Framework is built based on MVC Pattern which solves most of above mentioned Webforms problems by itself. Following are some of the best things MVC Framework offers on the front end –
1. No ViewState – MVC goes inline with web statelessness and eliminates ViewState to store Server Control states. It is also oriented towards resource driven like REST and it works mostly on actions rather than complete life cycle (you so a specific request and you get specific response). With MVC we have mush more better control on every Request we make to server.
2. Testability – With its natural componentization from MVC Pattern, MVC readily support good amount of Unit Testing. MVC generates clean Html which supports most of UI Automated Test tools.
3. User Friendly URLs – MVC generated search engine friendly and user intuitive URLs, which can be easily remembered and shared across Web.
5. Extensibility – MVC has greater flexibility to extend/replace components on which it is built on, for example View Engines you can opt for traditional ASP.Net View Engine or use Razor or any other view engines available. We can also write our own view engines too. MVC also incorporates major ASP.Net and .Net Frameworks APIs like Membership Providers, Roles etc.. which saves lot of time to ASP.Net Developers in writing code they are familiar with.
Last but not least, the main point of this blog post is not to exaggerate which technology is superior than the other. End of the day every technology has to make some trade offs, it is really very hard to conclude which is better. It all depends on how we use a particular technology to solve a business problem. Looking at these technologies (Webforms and MVC) and working closely with them, I saw both the frameworks solved wonderful problems in an elegant approach. Always use a right technology for a right business problem.
Republished from Rami Vemula [15 clicks].
Read the original version here [5 clicks].