Get MVC Razor favor .cshtml over .aspx

自作多情 提交于 2019-12-22 08:15:38

问题


I have converted a site over entirely to Razor and want it to ignore any residual .aspx files. These have caused problems by

  1. not being deleted from the production server and
  2. being recreated by NuGet packages. In this case, the ASPX takes precedence and any customization to the equivalent CSHTML file are not in play.

I would like to tell the entire site to stop processing ASPX or ASCX pages and only use Razor views.


回答1:


Add following to Global.asax.cs

protected void Application_Start()
{
    ViewEngines.Engines.Clear();
    ViewEngines.Engines.Add(new RazorViewEngine());
}

By default a WebFormViewEngine is included BEFORE RazorViewEngine.



来源:https://stackoverflow.com/questions/8434015/get-mvc-razor-favor-cshtml-over-aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!