Make ASP.NET MVC 3 Razor View Engine ignore .vbhtml files

后端 未结 7 916
情深已故
情深已故 2020-12-24 09:02

How can I remove the VB Razor Engine or configure the RazorViewEngine to not use and look for .vbhtml files on disk? For new ASP.NET MVC 3 Razor projects, I always remove th

7条回答
  •  醉话见心
    2020-12-24 09:42

    Why is there no point in removing search in .vbhtml if I'm never going to use it?

    Here is how I do it (but I still don't know is it a good thing to remove vbhtml):

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

    Extension method code:

    public static RazorViewEngine DisableVbhtml(this RazorViewEngine engine)
    {
        engine.AreaViewLocationFormats = FilterOutVbhtml(engine.AreaViewLocationFormats);
        engine.AreaMasterLocationFormats = FilterOutVbhtml(engine.AreaMasterLocationFormats);
        engine.AreaPartialViewLocationFormats = FilterOutVbhtml(engine.AreaPartialViewLocationFormats);
        engine.ViewLocationFormats = FilterOutVbhtml(engine.ViewLocationFormats);
        engine.MasterLocationFormats = FilterOutVbhtml(engine.MasterLocationFormats);
        engine.PartialViewLocationFormats = FilterOutVbhtml(engine.PartialViewLocationFormats);
        engine.FileExtensions = FilterOutVbhtml(engine.FileExtensions);
    
        return engine;
    }
    
    private static string[] FilterOutVbhtml(string[] source)
    {
        return source.Where(s => !s.Contains("vbhtml")).ToArray();
    }
    

提交回复
热议问题