获得 MVC Razor 青睐 .cshtml 而不是 .aspx [英] Get MVC Razor favor .cshtml over .aspx
本文介绍了获得 MVC Razor 青睐 .cshtml 而不是 .aspx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已将一个站点完全转换为 Razor,并希望它忽略任何残留的 .aspx 文件.这些问题由
I have converted a site over entirely to Razor and want it to ignore any residual .aspx files. These have caused problems by
- 未被从生产服务器中删除和
- 由 NuGet 包重新创建.在这种情况下,ASPX 优先,对等效 CSHTML 文件的任何自定义都不起作用.
我想告诉整个网站停止处理 ASPX 或 ASCX 页面,只使用 Razor 视图.
I would like to tell the entire site to stop processing ASPX or ASCX pages and only use Razor views.
推荐答案
在 Global.asax.cs 中添加以下内容
Add following to Global.asax.cs
protected void Application_Start()
{
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
}
默认情况下,WebFormViewEngine
包含在 RazorViewEngine
之前.
By default a WebFormViewEngine
is included BEFORE RazorViewEngine
.
这篇关于获得 MVC Razor 青睐 .cshtml 而不是 .aspx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文