Skip to content

Commit 1712982

Browse files
authored
Add two missing methods for VirtualPathProvider (#562)
1 parent 57eaf06 commit 1712982

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,10 +1004,12 @@ public abstract partial class VirtualPathProvider
10041004
public virtual bool DirectoryExists(string virtualDir) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
10051005
public virtual bool FileExists(string virtualPath) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
10061006
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");}
1007+
public virtual string GetCacheKey(string virtualPath) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
10071008
public virtual System.Web.Hosting.VirtualDirectory GetDirectory(string virtualDir) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
10081009
public virtual System.Web.Hosting.VirtualFile GetFile(string virtualPath) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
10091010
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");}
10101011
protected virtual void Initialize() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
1012+
public static System.IO.Stream OpenFile(string virtualPath) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
10111013
}
10121014
}
10131015
namespace System.Web.Security

src/Microsoft.AspNetCore.SystemWebAdapters/Hosting/VirtualPathProvider.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections;
5+
using System.IO;
56
using System.Web.Caching;
67
using System.Web.Util;
78

@@ -53,6 +54,12 @@ protected virtual void Initialize()
5354

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

57+
public virtual string? GetCacheKey(string virtualPath)
58+
{
59+
// By default, return null, meaning use a key based on the virtual path
60+
return null;
61+
}
62+
5663
public virtual string CombineVirtualPaths(string basePath, string relativePath)
5764
{
5865
if (string.IsNullOrEmpty(basePath))
@@ -65,4 +72,14 @@ public virtual string CombineVirtualPaths(string basePath, string relativePath)
6572
// By default, just combine them normally
6673
return VirtualPathUtility.Combine(baseDir, relativePath);
6774
}
75+
76+
/*
77+
* Helper method to open a file from its virtual path
78+
*/
79+
public static Stream? OpenFile(string virtualPath)
80+
{
81+
VirtualPathProvider? vpathProvider = HostingEnvironment.VirtualPathProvider;
82+
VirtualFile? vfile = vpathProvider?.GetFileWithCheck(virtualPath);
83+
return vfile?.Open();
84+
}
6885
}

0 commit comments

Comments
 (0)