Example #1
0
 /// <summary>
 /// 构建一个虚拟路径对象
 /// </summary>
 /// <param name="virtualPath">虚拟路径</param>
 /// <param name="isDirectory">是否是目录,默认为文件路径</param>
 /// <param name="rootPathType"></param>
 public VirtualPath(string virtualPath, bool isDirectory = false, RootPathType rootPathType = RootPathType.WebRootPath)
 {
     if (string.IsNullOrEmpty(virtualPath))
     {
         throw new ArgumentNullException(nameof(virtualPath));
     }
     _virtualPath  = virtualPath;
     _isDirectory  = isDirectory;
     _rootPathType = rootPathType;
     if (string.IsNullOrEmpty(WebRootPath) && string.IsNullOrEmpty(ContentRootPath))
     {
         var hostingEnvironment = HttpContext.Current.RequestServices.GetRequiredService <IHostingEnvironment>();
         WebRootPath     = hostingEnvironment.WebRootPath;
         ContentRootPath = hostingEnvironment.ContentRootPath;
     }
     _rootPath = _rootPathType == RootPathType.WebRootPath ? WebRootPath : ContentRootPath;
 }
Example #2
0
 /// <summary>
 /// 创建一个类型为目录的对象,起始路径为根节点
 /// </summary>
 /// <param name="rootPathType"></param>
 public VirtualPath(RootPathType rootPathType = RootPathType.WebRootPath) : this("/", true, rootPathType)
 {
 }