In this article we will learn how to remove View Engines which is not being used by application.
Why need to remove?
If we remove View Engines which is not being used by application, then it lead to improve the performance in our application.
- In default, MVC will search the webform (.aspx) view engine first to find the match naming conventions. After that it start to search for the views that match the Razor view engine naming conventions like below
Example : 1
Here i am creating a new controller with default action, but i don’t add view for this action method.
public class SampleController : Controller
public ActionResult Index()
In this situation i am try to run the application to access the sample controller, then it will show output as shown below
Example : 2
Let we removing the view engines and register only Razor view engine, by given code below
protected void Application_Start()
- It can control by placing it in Global.asax file.
- All Engine will be clear by using ViewEngines.Engines.Clear().
- ViewEngines.Engines.Add(new RazorViewEngine()) it will again register razor view engine to the application