使用剃须刀时关闭WebFormViewEngine?

Nic*_*sen 46 asp.net-mvc configuration webforms razor

我今天早上下载了Glimpse进行试用,并在点击"视图"标签时注意到了这一点:

一瞥视图选项卡

它会检查所有已加载的视图引擎.我找到了RazorViewEngineweb.config中指定的位置,但我找不到它的WebFormViewEngine位置.因为我知道我的项目永远不会有网页表单视图,

  1. 关闭是否可以/安全WebFormViewEngine
  2. 我怎么能关掉WebFormViewEngine

Muh*_*hid 73

如果您不使用它,那么删除Web窗体视图引擎是完全可以的.你可以这样做:

public class Global : HttpApplication
{
    public void Application_Start()
    {
        // Clears all previously registered view engines.
        ViewEngines.Engines.Clear();

        // Registers our Razor C# specific view engine.
        // This can also be registered using dependency injection through the new IDependencyResolver interface.
        ViewEngines.Engines.Add(new RazorViewEngine());
    }
}
Run Code Online (Sandbox Code Playgroud)

上面的方法调用进入你的global.asax文件.

的源代码


gra*_*esd 14

另一种方法是仅删除要删除的视图引擎:

    var webformVE = ViewEngines.Engines.OfType<WebFormViewEngine>().FirstOrDefault();
    ViewEngines.Engines.Remove(webformVE);
Run Code Online (Sandbox Code Playgroud)