ASP. NET MVC removal of unused view engines

Source: Internet
Author: User

ASP. NET MVC provides two view engines by default, namely: Webformviewengine and Razorviewengine. When MVC finds views, it finds them in the order specified. When our MVC program does not find the appropriate view, the following error message appears in the page:

It is known that the WebForm view engine is the first to perform the search, followed by the Razor view engine. In our MVC project, we usually use only one of the razor or webform (most of them are razor). If we only use razor in our project, it would be superfluous to perform the WebForm view engine lookup in this case. That being the case, we can avoid this extra action by removing the WebForm view engine (more or less to improve performance). The removal operation is simple, just add the following code to the Application_Start () function in the Global.asax file:

protected void Application_Start () {      // omit other code      in function //  Clear all View engines       ViewEngines.Engines.Clear ();       //       ViewEngines.Engines.Add (new  razorviewengine ());}

Now we run our MVC program again, and when the corresponding view is not found, the error message in the page is as follows:

As the diagram shows, Webformviewengine has been successfully removed, so the program does not have to look for webformviewengine related views.

ASP. NET MVC removal of unused view engines

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.