Ejemplo n.º 1
0
        /// <summary>
        /// 获取指定虚拟路径的 HTML 处理程序
        /// </summary>
        /// <param name="virtualPath">要获取 HTML 处理程序的虚拟路径</param>
        /// <returns>HTML 处理程序</returns>
        public static IHtmlHandler GetHandler(string virtualPath)
        {
            var services = WebServiceLocator.GetServices <IHtmlHandlerProvider>(virtualPath);

            foreach (var provider in services)
            {
                var handler = provider.GetHandler(virtualPath);

                if (handler != null)
                {
                    return(handler);
                }
            }


            if (!HostingEnvironment.VirtualPathProvider.FileExists(virtualPath))//如果文件不存在,则直接返回 null 。
            {
                return(null);
            }


            return
                (GetHandlerInternal <IHtmlHandler>(virtualPath + ".ashx") ??
                 GetHandlerInternal <IHtmlHandler>(GetHandlerPath(virtualPath)) ??
                 GetHandlerInternal <IHtmlHandler>(VirtualPathHelper.FallbackSearch(virtualPath, "_handler.ashx")));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取视图处理程序
        /// </summary>
        /// <param name="virtualPath">视图的虚拟路径</param>
        /// <param name="includeDefaultHandler">是否要查找默认视图处理程序</param>
        /// <returns>该虚拟路径的视图处理程序</returns>
        internal static IViewHandler GetViewHandlerInternal(string virtualPath, bool includeDefaultHandler)
        {
            var handler = GetHandlerInternal(virtualPath);

            if (handler == null && !includeDefaultHandler)
            {
                handler = GetHandlerInternal(VirtualPathHelper.FallbackSearch(virtualPath, "_handler.ashx"));
            }

            return(handler ?? new ViewHandler());
        }
Ejemplo n.º 3
0
        private string FindMasterView(string directory)
        {
            string masterPath;

            if (MvcEnvironment.Configuration.FallbackDefaultMaster)
            {
                masterPath = VirtualPathHelper.FallbackSearch(VirtualPathProvider, directory, "_master.html");
            }

            else
            {
                masterPath = VirtualPathUtility.Combine(directory, "_master.html");
                if (!VirtualPathProvider.FileExists(masterPath))
                {
                    masterPath = null;
                }
            }


            return(masterPath);
        }