为了账号安全,请及时绑定邮箱和手机立即绑定

PrecompiledMvc​​Engine 仍然使用共享物理视图

PrecompiledMvc​​Engine 仍然使用共享物理视图

C#
扬帆大鱼 2021-06-03 13:05:24
我已经在 app start 中注册了一个 PrecompilecMvcEngine 来预编译我的剃刀视图。构建包正确地排除了 ~/Views/ 目录中的所有 .cshtml 文件,但如果目录中存在视图,它会继续使用 .cshtml 文件,无论是否编译。例如,如果部署目录中存在视图 ~/Shared/Layout.cshtml,则始终使用该视图。如何确保从不使用物理视图?我有以下代码:[assembly: WebActivatorEx.PostApplicationStartMethod(typeof(SomeBaseNamespace.Views.RazorGeneratorMvcStart), "Start")]namespace SomeBaseNamespace.Views{    public static class RazorGeneratorMvcStart    {        public static void Start()        {            var engine = new PrecompiledMvcEngine(typeof(RazorGeneratorMvcStart).Assembly)             {                UsePhysicalViewsIfNewer = false // I would expect this to prevent the engine from using physical views.            };            ViewEngines.Engines.Insert(0, engine);        }    }}
查看完整描述

1 回答

?
炎炎设计

TA贡献1808条经验 获得超4个赞

正如CodeCaster所写,设置PreemptPhysicalFilestrueonPrecompiledMvcEngine解决了这个问题。


查看完整回答
反对 回复 2021-06-05
  • 1 回答
  • 0 关注
  • 211 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信