Turning off the WebFormViewEngine when using razor?

不问归期 提交于 2019-12-31 08:41:47

问题


I downloaded Glimpse this morning to try it out and noticed this when I click on the views tab:

It checks all of the loaded view engines. I found where the RazorViewEngine is specified in web.config, but I couldn't find where the WebFormViewEngine was. Since I know my project will never have an web form view in it,

  1. Is it ok/safe to turn off WebFormViewEngine?
  2. How can I turn off WebFormViewEngine?

回答1:


It is perfectly OK to remove the web forms view engine if you are not using it. You can do it like:

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());
    }
}

The above method calls go in your global.asax file.

source of code




回答2:


An alternative would be to remove only the view engine you want to remove:

    var webformVE = ViewEngines.Engines.OfType<WebFormViewEngine>().FirstOrDefault();
    ViewEngines.Engines.Remove(webformVE);


来源:https://stackoverflow.com/questions/5912980/turning-off-the-webformviewengine-when-using-razor

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