Monday, 30 January 2017

Can you remove default View Engine in ASP.NET MVC? How?

We can customize view engines in ASP.NET MVC application.

If you are not using any view engine like ASPX View Engine, better you remove it to improve the performance, it is one of the MVC performance tuning tips from the bunch.

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 below.

  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. }

  1. After removing Web Form engine, Razor View Engine will be almost 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.
You can also customize the view engines. for more click 


Note: only a member of this blog may post a comment.