Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1004,10 +1004,12 @@ public abstract partial class VirtualPathProvider
public virtual bool DirectoryExists(string virtualDir) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public virtual bool FileExists(string virtualPath) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public virtual System.Web.Caching.CacheDependency GetCacheDependency(string virtualPath, System.Collections.IEnumerable virtualPathDependencies, System.DateTime utcStart) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public virtual string GetCacheKey(string virtualPath) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public virtual System.Web.Hosting.VirtualDirectory GetDirectory(string virtualDir) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public virtual System.Web.Hosting.VirtualFile GetFile(string virtualPath) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public virtual string GetFileHash(string virtualPath, System.Collections.IEnumerable virtualPathDependencies) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
protected virtual void Initialize() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public static System.IO.Stream OpenFile(string virtualPath) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
}
}
namespace System.Web.Security
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections;
using System.IO;
using System.Web.Caching;
using System.Web.Util;

Expand Down Expand Up @@ -53,6 +54,12 @@ protected virtual void Initialize()

public virtual VirtualDirectory? GetDirectory(string virtualDir) => Previous?.GetDirectory(virtualDir);

public virtual string? GetCacheKey(string virtualPath)
{
// By default, return null, meaning use a key based on the virtual path
return null;
}

public virtual string CombineVirtualPaths(string basePath, string relativePath)
{
if (string.IsNullOrEmpty(basePath))
Expand All @@ -65,4 +72,14 @@ public virtual string CombineVirtualPaths(string basePath, string relativePath)
// By default, just combine them normally
return VirtualPathUtility.Combine(baseDir, relativePath);
}

/*
* Helper method to open a file from its virtual path
*/
public static Stream? OpenFile(string virtualPath)
{
VirtualPathProvider? vpathProvider = HostingEnvironment.VirtualPathProvider;
VirtualFile? vfile = vpathProvider?.GetFileWithCheck(virtualPath);
return vfile?.Open();
}
}