/// <summary> /// 加载 HTML 文档 /// </summary> /// <param name="virtualPath">文档的虚拟路径</param> /// <param name="cacheDependency">若文档已被缓存,获取缓存依赖项</param> /// <returns>HTML 文档对象</returns> public static IHtmlDocument LoadDocument(string virtualPath, out CacheDependency cacheDependency) { string cacheKey; var result = LoadDocument(virtualPath, out cacheKey); if (result == null) { cacheDependency = null; return(result); } if (cacheKey != null) { cacheDependency = new CacheDependency(new string[0], new string[] { cacheKey }); } else { cacheDependency = HtmlServices.CreateCacheDependency(virtualPath); } return(result); }
/// <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); }
/// <summary> /// 利用指定 VirtualPathProvider 将虚拟路径所指向文件当作静态文件加载。 /// </summary> /// <param name="provider">指定的 VirtualPathProvider</param> /// <param name="virtualPath">虚拟路径</param> /// <returns>加载结果</returns> public HtmlContentResult LoadContent(VirtualPathProvider provider, string virtualPath) { if (!VirtualPathUtility.IsAppRelative(virtualPath)) { return(null); } if (!provider.FileExists(virtualPath)) { return(null); } var file = provider.GetFile(virtualPath); if (file == null) { return(null); } var key = provider.GetCacheKey(virtualPath) ?? "StaticFile_" + virtualPath; var content = HttpRuntime.Cache.Get(key) as string; if (content == null) { var dependency = HtmlServices.CreateCacheDependency(provider, virtualPath); content = LoadContent(file); HttpRuntime.Cache.Insert(key, content, dependency); } return(new HtmlContentResult(content, key)); }