2013年2月15日 星期五

書籍寫的 加速MVC的方法1

移除Aspx View Engine 在Razor環境下


// 移除ASPX View Engine 加快速度
            ViewEngines.Engines.RemoveAt(0);

            var razorViewEngine = ViewEngines.Engines[0] as RazorViewEngine;

            razorViewEngine.AreaMasterLocationFormats = razorViewEngine.AreaMasterLocationFormats.Where(x => x.EndsWith("cshtml")).ToArray();
            razorViewEngine.AreaPartialViewLocationFormats = razorViewEngine.AreaPartialViewLocationFormats.Where(x => x.EndsWith("cshtml")).ToArray();
            razorViewEngine.AreaViewLocationFormats = razorViewEngine.AreaViewLocationFormats.Where(x => x.EndsWith("cshtml")).ToArray();

            razorViewEngine.FileExtensions = razorViewEngine.FileExtensions.Where(x => x.EndsWith("cshtml")).ToArray();
            razorViewEngine.MasterLocationFormats = razorViewEngine.MasterLocationFormats.Where(x => x.EndsWith("cshtml")).ToArray();
            razorViewEngine.PartialViewLocationFormats = razorViewEngine.PartialViewLocationFormats.Where(x => x.EndsWith("cshtml")).ToArray();

            razorViewEngine.ViewLocationFormats = razorViewEngine.ViewLocationFormats.Where(x => x.EndsWith("cshtml")).ToArray();