Exemple #1
0
        /// <summary>注册需要搜索的目录路径</summary>
        /// <param name="engines"></param>
        public static void Register(ViewEngineCollection engines)
        {
            // 如果没有注册,则注册
            var ve = engines.FirstOrDefault(e => e is RazorViewEngineX) as RazorViewEngineX;

            if (ve == null)
            {
                // 干掉旧引擎,使用新引擎
                var ve2 = engines.FirstOrDefault(e => e is RazorViewEngine);
                engines.Remove(ve2);

                ve = new RazorViewEngineX();
                engines.Insert(0, ve);

                XTrace.WriteLine("注册视图引擎:{0}", ve.GetType().FullName);
            }
        }
        public static void Configure(ViewEngineCollection engines)
        {
            var razorEngine = engines.FirstOrDefault(f => f.GetType() == typeof(RazorViewEngine));

            if (razorEngine != null)
            {
                engines.Remove(razorEngine);
            }
            engines.Add(new FeaturesRazorViewEngine());
        }
        /// <summary>The update view engines.</summary>
        /// <param name="engines">The engines.</param>
        private static void UpdateViewEngines(ViewEngineCollection engines)
        {
            var webFormViewEngine = engines.FirstOrDefault(e => e is WebFormViewEngine);

            if (webFormViewEngine != null)
            {
                engines.Remove(webFormViewEngine);
            }

            engines.OfType<RazorViewEngine>().ToList().ForEach(engine =>
                    engine.FilterLocationFormats(
                        e => e.AreaMasterLocationFormats, 
                        e => e.AreaPartialViewLocationFormats, 
                        e => e.AreaViewLocationFormats, 
                        e => e.FileExtensions, 
                        e => e.MasterLocationFormats, 
                        e => e.PartialViewLocationFormats, 
                        e => e.ViewLocationFormats));
        }