RSS

Remove unnecessary view engines if you don’t use them in ASP.NET MVC

22 Jul

Visual Studio 2012 MVC 4 internet project template by default supports Razor View engine out of the box where the views suffixed with cshtml extension created by default. If you further go through this route and use Razor view engine still ASP.NET MVC 4 default template uses web forms view engine by default before using Razor view engine when it comes to view resolution which has probably a little performance pay.
If you use Glimpse debugging plugin for ASP.NET MVC4 you can easily view this as shown below.
ASP.NET MVC View resolution in Glimpse

As you can see above web forms view engine by default used prior to Razor view engine. This might be a micro optimization but you should remove the web forms view engine if you are not using this as shown below or at least you should change the order if you are mostly using Razor views than web forms views.

protected void Application_Start()
		{
			AreaRegistration.RegisterAllAreas();

			WebApiConfig.Register(GlobalConfiguration.Configuration);
			FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
			RouteConfig.RegisterRoutes(RouteTable.Routes);
			BundleConfig.RegisterBundles(BundleTable.Bundles);
			AuthConfig.RegisterAuth();

			//Remove default view engines
			ViewEngines.Engines.Clear();
			// add the Razor view engine
			ViewEngines.Engines.Add(new RazorViewEngine());

		}

If you do this modification in Global.asax file you should see more efficient view resolution as shown below.
view engines in ASP.NET MVC

Advertisements
 
Leave a comment

Posted by on July 22, 2013 in ASP.NET, ASP.NET MVC

 

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: