Ejemplo n.º 1
0
        /// <summary>
        /// 创建页面视图
        /// </summary>
        /// <param name="controllerContext">控制器上下文</param>
        /// <param name="viewPath">视图路径</param>
        /// <param name="masterPath">母板路径</param>
        /// <exception cref="System.NotSupportedException">当 masterPath 参数不为空,且当前创建的视图不支持母板时引发</exception>
        /// <returns>页面视图对象</returns>
        protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
        {
            var view = CreateViewCore(controllerContext, viewPath, false);

            if (string.IsNullOrEmpty(masterPath))
            {
                var directory = VirtualPathUtility.GetDirectory(viewPath);

                if (MvcEnvironment.Configuration.FallbackDefaultMaster)
                {
                    masterPath = ViewHandlerProvider.FallbackSearch(VirtualPathProvider, directory, "_master.html");
                }
                else
                {
                    masterPath = VirtualPathUtility.Combine(directory, "_master.html");
                }

                if (VirtualPathProvider.FileExists(masterPath))
                {
                    var contentView = view as IContentView;

                    if (contentView != null)
                    {
                        contentView.InitializeMaster(CreateMaster(controllerContext, masterPath));
                        return(contentView);
                    }
                }

                return(view);
            }

            else
            {
                var contentView = view as IContentView;

                if (contentView == null)
                {
                    throw new InvalidOperationException("视图不支持母板");
                }

                contentView.InitializeMaster(CreateMaster(controllerContext, masterPath));

                return(contentView);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取视图处理程序
        /// </summary>
        /// <returns>视图处理程序</returns>
        protected virtual IViewHandler GetHandler(string virtualPath)
        {
            var cacheKey = handlerPathCachePrefix + virtualPath;

            var cacheItem = HttpRuntime.Cache.Get(cacheKey);

            if (cacheItem == null)
            {
                var handlerPath = ViewHandlerProvider.GetHandlerPath(Scope);

                cacheItem = new HandlerPathCacheItem()
                {
                    HandlerPath = handlerPath
                };

                HttpRuntime.Cache.Insert(cacheKey, cacheItem, ScopeCacheDependency);
            }


            return(ViewHandlerProvider.GetViewHandler(virtualPath));
        }
Ejemplo n.º 3
0
 protected override IViewHandler GetHandler(string virtualPath)
 {
     return(ViewHandlerProvider.GetMasterViewHandler(virtualPath));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 获取视图处理程序
 /// </summary>
 /// <returns>视图处理程序</returns>
 protected virtual IViewHandler GetHandler(string virtualPath)
 {
     return(ViewHandlerProvider.GetViewHandler(virtualPath));
 }