Friday, December 28, 2012

Asp.Net WebForm Vs Asp.Net MVC


Difference between Asp.Net WebForm and Asp.Net MVC

Asp.net framework is a part of .net platform for building, deploying and running web applications. Now, we can develop a web application by using Asp.Net Web Form and Asp.Net MVC. In this article, I am going to expose the main difference between Asp.Net Web Form and Asp.Net MVC.



Difference between Asp.Net MVC and Web Forms
Asp.Net Web Forms
Asp.Net MVC
Asp.Net Web Form follow a traditional event driven development model.
Asp.Net MVC is a lightweight and follow MVC (Model, View, Controller) pattern based development model.
Asp.Net Web Form has server controls.
Asp.Net MVC has html helpers.
Asp.Net Web Form has state management (like as view state, session) techniques.
Asp.Net MVC has no automatic state management techniques.
Asp.Net Web Form has file-based URLs means file name exist in the URLs must have its physically existence.
Asp.Net MVC has route-based URLs means URLs are divided into controllers and actions and moreover it is based on controller not on physical file.
Asp.Net Web Form follows Web Forms Syntax
Asp.Net MVC follow customizable syntax (Razor as default)
In Asp.Net Web Form, Web Forms(ASPX) i.e. views are tightly coupled to Code behind(ASPX.CS) i.e. logic.
In Asp.Net MVC, Views and logic are kept separately.
Asp.Net Web Form has Master Pages for consistent look and feels.
Asp.Net Web Form has Layouts for consistent look and feels.
Asp.Net Web Form has User Controls for code re-usability.
Asp.Net MVC has Partial Views for code re-usability.
Asp.Net Web Form has built-in data controls and best for rapid development with powerful data access.
Asp.Net MVC is lightweight, provide full control over markup and support many features that allow fast & agile development. Hence it is best for developing interactive web application with latest web standards.
Visual studio and Visual web developer(free) are tools for developing Asp.Net Web Forms.
Visual studio and Visual web developer(free) are tools for developing Asp.Net MVC application.
Asp.Net Web Form is not Open Source.
Asp.Net Web MVC is an Open Source.

Removing the Web Form View Engine for better performance of Razor View Engine

By default MVC is configured to resolve a view by searching the views that match the Web Form view engine's naming conventions first. After that MVC begins search for the views that match the Razor view engine's naming conventions as shown in below fig.

So, If are not using ASPX views in your MVC applications then the checking four unused locations first for every return View() and Html.RenderPartial is quite wasteful and time consuming. After removing Web Form engine, Razor View Engine will be twice as fast with the Web Form engine.

Removing the Web Form (ASPX) view engine

Removing the Web Form view engine is easy in MVC. We can remove all the view engines and add only Razor view engine by using Application_Start event of Global.asax.cs file like as:
  1. protected void Application_Start()
  2. {
  3. //Remove All Engine
  4. ViewEngines.Engines.Clear();
  5. //Add Razor Engine
  6. ViewEngines.Engines.Add(new RazorViewEngine());
  7. ...
  8. }
After removing all the view engines and register only Razor view engine, now MVC try to resolve a view by searching the views that match the Razor view engine's naming conventions only as shown in fig.

Note

  1. After removing Web Form engine, Razor View Engine will be twice as fast with the Web Form engine.
  2. Use this when you are sure that you will use only Razor views. It will be helpful to you.
  3. If you are using both type of views (ASPX & Razor), don't implement this.

No comments:

Post a Comment