Example #1
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);
        }
Example #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));
        }
Example #3
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 );
        }