Exemple #1
0
        /// <summary>
        /// 派生类可以重写此方法自定义加载虚拟路径处的文档的逻辑
        /// </summary>
        /// <returns></returns>
        protected virtual IHtmlDocument LoadDocument(string virtualPath, out CacheDependency cacheDependency)
        {
            string cacheKey;
            var    document = HtmlServices.LoadDocument(virtualPath, out cacheKey);

            if (cacheKey != null)
            {
                cacheDependency = new CacheDependency(new string[0], new string[] { cacheKey });
            }

            else
            {
                cacheDependency = HtmlServices.CreateCacheDependency(virtualPath);
            }

            return(document);
        }
Exemple #2
0
        /// <summary>
        /// 在 HTML 文档中查找 ViewHandler 路径设置。
        /// </summary>
        /// <param name="virtualPath">要处理的 HTML 文档的虚拟路径</param>
        /// <returns>用于处理 HTML 的视图处理程序路径</returns>
        public static string GetHandlerPath(string virtualPath)
        {
            var cacheKey = handlerPathCachePrefix + virtualPath;

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

            if (cacheItem == null)
            {
                string cacheDependencyKey;
                var    document = HtmlServices.LoadDocument(virtualPath, out cacheDependencyKey);

                if (document == null)
                {
                    return(null);
                }



                var head = document.FindFirstOrDefault("head");
                if (head == null)
                {
                    return(null);
                }

                var handlerMeta = head.FindFirstOrDefault("meta[name=handler]");
                if (handlerMeta == null)
                {
                    return(null);
                }

                var handlerPath = handlerMeta.Attribute("value").Value();


                if (cacheDependencyKey != null)
                {
                    cacheItem = new HandlerPathCacheItem()
                    {
                        HandlerPath = handlerPath
                    };
                    HttpRuntime.Cache.Insert(cacheKey, cacheItem, new CacheDependency(new string[0], new[] { cacheDependencyKey }));
                }
            }


            return(cacheItem.HandlerPath);
        }
Exemple #3
0
        /// <summary>
        /// 派生类重写此方法自定义加载文档的逻辑
        /// </summary>
        /// <param name="virtualPath">文档的虚拟路径</param>
        /// <returns>加载的文档对象</returns>
        protected virtual IHtmlDocument LoadDocument(string virtualPath)
        {
            IHtmlDocument document;

            Trace("Begin load document.");


            document = HtmlServices.LoadDocument(virtualPath);
            if (document == null)
            {
                throw new HttpException(404, "加载文档失败");
            }


            Trace("End load document.");

            return(document);
        }