Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turning off the WebFormViewEngine when using razor?

I downloaded Glimpse this morning to try it out and noticed this when I click on the views tab:

Glimpse Views Tab

It checks all of the loaded view engines. I found where the RazorViewEngine is specified in web.config, but I couldn't find where the WebFormViewEngine was. Since I know my project will never have an web form view in it,

  1. Is it ok/safe to turn off WebFormViewEngine?
  2. How can I turn off WebFormViewEngine?
like image 883
Nick Larsen Avatar asked May 06 '11 14:05

Nick Larsen


People also ask

Why use a razor when we have aspx?

Razor has new and advance syntax that are compact, expressive and reduces typing. Web Form Engine has the same syntax like Asp.net Web Forms uses for . aspx pages. By default, Razor Engine prevents XSS attacks(Cross-Site Scripting Attacks) means it encodes the script or html tags like <,> before rendering to view.

How can we remove the default 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.

Which one is faster ASPX or razor?

Aspx Engine is faster compared to Razor Engine.

How does a Razor View Engine work?

View Engine works inside the application for rendering HTML page to the browser or to the user. It can contain HTML tags, server controls and some programming language. Razor is preferred view engine for MVC4 framework.


1 Answers

It is perfectly OK to remove the web forms view engine if you are not using it. You can do it like:

public class Global : HttpApplication {     public void Application_Start()     {         // Clears all previously registered view engines.         ViewEngines.Engines.Clear();          // Registers our Razor C# specific view engine.         // This can also be registered using dependency injection through the new IDependencyResolver interface.         ViewEngines.Engines.Add(new RazorViewEngine());     } } 

The above method calls go in your global.asax file.

source of code

like image 148
Muhammad Adeel Zahid Avatar answered Oct 25 '22 06:10

Muhammad Adeel Zahid