Removal of the APSX view engine and the role of Web. config in the view directory

Source: Internet
Author: User

<>

Remove the APSX view engine when using the Rezor view engine

Global.asax file

Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Http;using    System.web.mvc;using System.web.routing;namespace mvcapp{//NOTE: For instructions on enabling IIS6 or IIS7 Classic mode. Please visit http://go.microsoft.com/?        linkid=9394801 public class MvcApplication:System.Web.HttpApplication {protected void Application_Start ()            {Arearegistration.registerallareas ();            Webapiconfig.register (globalconfiguration.configuration);            Filterconfig.registerglobalfilters (globalfilters.filters);            Routeconfig.registerroutes (routetable.routes); Normally we use the Razor view engine, so there's no need for MVC to find the ASPX view engine. So you can remove the ASPX view engine. This will be a bit faster each time the view is loaded (it is performance-intensive to find the ASPX view engine each time the view is loaded.) We were able to create a Home controller without creating an index view of it, and when we visited/home/index, we were prompted to find the view, and we were able to see that MVC was looking for the ASPX and razor views. Not found. Will not find the view error)//Why should the removal of the view engine code in this Global.asax file?            That's because the site started, I'll remove it first.            Removal of the ASPX View engine//viewengines.engines.removeat (0); This is a one-time razor view engine            ViewEngines.Engines.RemoveAt (1); }    }}


In the MVC project, we found that there is also a Web. config file in the view, so what does this configuration file do?

We see the view. It is essentially a front-end class that compiles it into a front-end page class when our view engine finds it for the first time. You need to inherit this front-end page class from a webviewpage<tmodel> generic class, or Webviewpage class (note: The Webviewpage class is the parent class of the Webviewpage<tmodel> Class)

(after reading the following code.) We will find that the parent class of the front-end page class generated after the view is compiled is specified in the Web. config file below the view directory)

We open this Web. config file and we can see that there's a

    <pages pagebasetype= "System.Web.Mvc.WebViewPage" >      <namespaces>        <add namespace= " SYSTEM.WEB.MVC "/>        <add namespace=" System.Web.Mvc.Ajax "/> <add namespace=        " System.Web.Mvc.Html "/>        <add namespace=" System.Web.Routing "/>      </namespaces>    </pages>
If we delete the Web. config file in this view directory, we will explode the following error


Let's visit a view page. For example, when/home/index. The view engine compiles the index view. When compiled, it is found that the view is found, it does not know who is the parent of the front page class compiled


So come to the conclusion: the role of the Web. config file below the view directory is to tell the view engine how to compile the view's foreground page class. and the parent class of the current page class is Webviewpage

The configuration in this web. config does not require us to manually change anything or delete


Removal of the APSX view engine and the role of Web. config in the view directory

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.