获取虚拟路径的类

来源:互联网 发布:淘宝古装 编辑:程序博客网 时间:2024/04/29 23:17
 获取虚拟路径的类
 if (HostingEnvironment.VirtualPathProvider.FileExists(virtualPath)) {
                    Type compiledType 
= null;
                    
try {
                        compiledType 
= BuildManager.GetCompiledType(virtualPath);
                        
                        
if (compiledType == null{
                            
object page = BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(System.Web.UI.Page));
                            compiledType 
= page.GetType();
                        }


                    }

                    
catch (SecurityException) {
                        
                        
                    }


                    
if (compiledType != null{
                        data 
= new WebServiceData(compiledType, pageMethods);   //放入缓存,依赖对象为页面所依赖的子页面。                  
                        BuildDependencySet deps 
= BuildManager.GetCachedBuildDependencySet(context, virtualPath);
                        IEnumerable virtualPaths 
= deps.VirtualPaths;
                        
if (virtualPaths != null{
                            List
<string> paths = new List<string>();
                            
foreach (string path in virtualPaths) {
                                paths.Add(Path.Combine(context.Request.PhysicalApplicationPath, VirtualPathUtility.GetFileName(path)));
                            }

                            context.Cache.Insert(cacheKey, data, 
new CacheDependency(paths.ToArray()));
                        }

                        
else {
                            context.Cache.Insert(cacheKey, data);
                        }

                    }

                }