Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
687 lines (577 sloc) 47.4 KB
<Type Name="VirtualPathProvider" FullName="System.Web.Hosting.VirtualPathProvider">
<TypeSignature Language="C#" Value="public abstract class VirtualPathProvider : MarshalByRefObject" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi abstract beforefieldinit VirtualPathProvider extends System.MarshalByRefObject" />
<TypeSignature Language="DocId" Value="T:System.Web.Hosting.VirtualPathProvider" />
<TypeSignature Language="VB.NET" Value="Public MustInherit Class VirtualPathProvider&#xA;Inherits MarshalByRefObject" />
<TypeSignature Language="C++ CLI" Value="public ref class VirtualPathProvider abstract : MarshalByRefObject" />
<TypeSignature Language="F#" Value="type VirtualPathProvider = class&#xA; inherit MarshalByRefObject" />
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.MarshalByRefObject</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>Provides a set of methods that enable a Web application to retrieve resources from a virtual file system.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Hosting.VirtualPathProvider> class provides a set of methods for implementing a virtual file system for a Web application. In a virtual file system, the files and directories are managed by a data store other than the file system provided by the server's operating system. For example, you can use a virtual file system to store content in a SQL Server database.
You can store any file that is processed on request in a virtual file system. This includes:
- ASP.NET pages, master pages, user controls, and other objects.
- Standard Web pages with extensions such as .htm and .jpg.
- Any custom extension mapped to a <xref:System.Web.Compilation.BuildProvider> instance.
- Any named theme in the `App_Theme` folder.
You cannot store ASP.NET application folders or files that generate application-level assemblies in a virtual file system. This includes:
- The Global.asax file.
- Web.config files.
- Site map data files used by the <xref:System.Web.XmlSiteMapProvider>.
- Directories that contain application assemblies or that generate application assemblies: `Bin`, `App_Code`, `App_GlobalResources`, any `App_LocalResources`.
- The application data folder, `App_Data`.
> [!NOTE]
> If a Web site is precompiled for deployment, content provided by a <xref:System.Web.Hosting.VirtualPathProvider> instance is not compiled, and no <xref:System.Web.Hosting.VirtualPathProvider> instances are used by the precompiled site.
## Registering a VirtualPathProvider
A custom <xref:System.Web.Hosting.VirtualPathProvider> instance should be registered with the ASP.NET compilation system by using the <xref:System.Web.Hosting.HostingEnvironment.RegisterVirtualPathProvider%2A?displayProperty=nameWithType> method before any page parsing or compilation is performed by the Web application.
Typically, a <xref:System.Web.Hosting.VirtualPathProvider> instance is registered in an `AppInitialize` method defined in the `App_Code` directory, or during the `Application_Start` event in the `Global.asax` file. For an example of registering a <xref:System.Web.Hosting.VirtualPathProvider> instance in an `AppInitialize` method, see the Example section.
You can register a <xref:System.Web.Hosting.VirtualPathProvider> instance during other events, but pages compiled and cached before the <xref:System.Web.Hosting.VirtualPathProvider> instance is registered will not be invalidated, even if the new <xref:System.Web.Hosting.VirtualPathProvider> instance would now provide the source for the previously compiled page.
## Examples
The following code example is a <xref:System.Web.Hosting.VirtualPathProvider> class implementation that creates a virtual file system using information stored in a <xref:System.Data.DataSet> object. The code example works with the code examples for the <xref:System.Web.Hosting.VirtualFile> and <xref:System.Web.Hosting.VirtualDirectory> classes to provide virtual resources from a data store that is loaded into a <xref:System.Data.DataSet> object.
This example has four parts: the <xref:System.Web.Hosting.VirtualPathProvider> class implementation, an XML data file used to populate the <xref:System.Data.DataSet> object, an `AppStart` object that contains an `AppInitialize` method used to register the <xref:System.Web.Hosting.VirtualPathProvider> class with the compilation system, and an ASP.NET page that provides links to the virtual files.
To use this sample code in an application, follow these steps.
1. Create a sample application on your Web server.
2. Copy the source code for the custom <xref:System.Web.Hosting.VirtualPathProvider> object (see below) into a file in the application's `App_Code` directory.
3. Copy the source code for the custom <xref:System.Web.Hosting.VirtualDirectory> object (see the Example section in the <xref:System.Web.Hosting.VirtualDirectory> class overview topic) into a file in the application's `App_Code` directory.
4. Copy the source code for the custom <xref:System.Web.Hosting.VirtualFile> object (see the Example section in the <xref:System.Web.Hosting.VirtualFile> class overview topic) into a file in the application's `App_Code` directory.
5. Copy the source code for the `AppStart` object (see below) into a file in the application's `App_Code` directory.
6. Copy the XML data (see below) into a file named `XMLData.xml` into a file in the application's `App_Data` directory.
7. Copy the `default.aspx` file (see below) into the root directory of the sample application. Use a Web browser to open the `default.aspx` file, and then click the links on the page to see the contents of the virtual files.
The first example is a custom <xref:System.Web.Hosting.VirtualPathProvider> class. The <xref:System.Web.Hosting.VirtualPathProvider.DirectoryExists%2A> and <xref:System.Web.Hosting.VirtualPathProvider.FileExists%2A> methods are overridden to indicate whether a requested directory is present in the virtual file system. The <xref:System.Web.Hosting.VirtualPathProvider.GetDirectory%2A> and <xref:System.Web.Hosting.VirtualPathProvider.GetFile%2A> methods are overridden to return custom <xref:System.Web.Hosting.VirtualDirectory> and <xref:System.Web.Hosting.VirtualFile> instances containing information from the virtual file system.
The class also provides a `GetVirtualData` method used by the <xref:System.Web.Hosting.VirtualDirectory> and <xref:System.Web.Hosting.VirtualFile> classes to access the <xref:System.Data.DataSet> object containing the virtual file system data. In a production implementation, this method would typically be implemented in a business object responsible for interacting with the data store.
[!code-csharp[System.Web.Hosting.VirtualPathProvider#20](~/samples/snippets/csharp/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/CS/SamplePathProvider.cs#20)]
[!code-vb[System.Web.Hosting.VirtualPathProvider#20](~/samples/snippets/visualbasic/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/VB/SamplePathProvider.vb#20)]
The second example is the XML data file used to populate the <xref:System.Data.DataSet> object returned by the custom <xref:System.Web.Hosting.VirtualPathProvider> object. This XML data is used to demonstrate using the <xref:System.Web.Hosting.VirtualPathProvider>, <xref:System.Web.Hosting.VirtualDirectory>, and <xref:System.Web.Hosting.VirtualFile> objects to retrieve data from external data and is not intended to represent a production-quality data store.
```
<?xml version="1.0" encoding="utf-8" ?>
<resource type="dir"
path="/vrDir"
parentPath=""
content="">
<resource type="file"
path="/vrDir/Level1FileA.vrf"
parentPath="/vrDir"
content="This is the content of file Level1FileA.">
</resource>
<resource type="file"
path="/vrDir/Level1FileB.vrf"
parentPath="/vrDir"
content="This is the content of file Level1FileB.">
</resource>
<resource type="dir"
path="/vrDir/Level2DirA"
parentPath="/vrDir"
content="">
<resource type="file"
path="/vrDir/Level2DirA/Level2FileA.vrf"
parentPath="/vrDir/Level2DirA"
content="This is the content of file Level2FileA.">
</resource>
<resource type="file"
path="/vrDir/Level2DirA/Level2FileB.vrf"
parentPath="/vrDir/Level2DirA"
content="This is the content of file Level2FileB.">
</resource>
</resource>
<resource type="dir"
path="/vrDir/Level2DirB"
parentPath="/vrDir"
content="">
<resource type="file"
path="/vrDir/Level2DirB/Level2FileA.vrf"
parentPath="/vrDir/Level2DirB"
content="This is the content of file Level2FileA.">
</resource>
<resource type="file"
path="/vrDir/Level2DirB/Level2FileB.vrf"
parentPath="/vrDir/Level2DirB"
content="This is the content of file Level2FileB.">
</resource>
</resource>
</resource>
```
The third example provides an `AppStart` object that contains an `AppInitialize` method. This method is called during the initialization of an ASP.NET application to perform any custom initialization required. In this case, it registers the custom <xref:System.Web.Hosting.VirtualPathProvider> object with the ASP.NET build system.
[!code-csharp[System.Web.Hosting.VirtualPathProvider#10](~/samples/snippets/csharp/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/CS/AppStart.cs#10)]
[!code-vb[System.Web.Hosting.VirtualPathProvider#10](~/samples/snippets/visualbasic/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/VB/AppStart.vb#10)]
The last example is an ASP.NET page that contains links to the virtual files contained in the virtual file system.
[!code-aspx-csharp[System.Web.Hosting.VirtualPathProvider#1](~/samples/snippets/csharp/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/CS/Default.aspx#1)]
[!code-aspx-vb[System.Web.Hosting.VirtualPathProvider#1](~/samples/snippets/visualbasic/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/VB/Default.aspx#1)]
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>When you inherit from <see cref="T:System.Web.Hosting.VirtualPathProvider" />, you must override the following members:
- <see cref="M:System.Web.Hosting.VirtualPathProvider.FileExists(System.String)" />
- <see cref="M:System.Web.Hosting.VirtualPathProvider.GetFile(System.String)" />
If your custom <see cref="T:System.Web.Hosting.VirtualPathProvider" /> class supports directories in the virtual file system, you must override the following members.
- <see cref="M:System.Web.Hosting.VirtualPathProvider.DirectoryExists(System.String)" />
- <see cref="M:System.Web.Hosting.VirtualPathProvider.GetDirectory(System.String)" /><block subset="none" type="note"><para>
If your virtual file system will contain themes for the Web site (by creating a virtual <c>App_Themes</c> directory), your custom <see cref="T:System.Web.Hosting.VirtualPathProvider" /> class must support directories.
</para></block>
A custom <see cref="T:System.Web.Hosting.VirtualPathProvider" /> class works with classes derived from the <see cref="T:System.Web.Hosting.VirtualFile" /> and <see cref="T:System.Web.Hosting.VirtualDirectory" /> classes. You should implement derived classes from these types to provide file and directory information from your virtual file system. For an example of a custom <see cref="T:System.Web.Hosting.VirtualFile" /> implementation, see the Example section of the <see cref="T:System.Web.Hosting.VirtualFile" /> class overview topic. For an example of a custom <see cref="T:System.Web.Hosting.VirtualDirectory" /> implementation, see the Example section of the <see cref="T:System.Web.Hosting.VirtualDirectory" /> class overview topic.</para>
</block>
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="protected VirtualPathProvider ();" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Hosting.VirtualPathProvider.#ctor" />
<MemberSignature Language="VB.NET" Value="Protected Sub New ()" />
<MemberSignature Language="C++ CLI" Value="protected:&#xA; VirtualPathProvider();" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName>System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<Parameters />
<Docs>
<summary>Initializes the class for use by an inherited class instance. This constructor can be called only by an inherited class.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
When overriding the <xref:System.Web.Hosting.VirtualPathProvider.%23ctor%2A> constructor, defer any initialization that must occur after the <xref:System.Web.Hosting.VirtualPathProvider> object is registered to the <xref:System.Web.Hosting.VirtualPathProvider.Initialize%2A> method.
## Examples
The following code example is an implementation of the <xref:System.Web.Hosting.VirtualPathProvider.%23ctor%2A> constructor that initializes a custom <xref:System.Web.Hosting.VirtualPathProvider> class. For the full code required to run the example, see the Example section of the <xref:System.Web.Hosting.VirtualPathProvider> class overview topic.
[!code-csharp[System.Web.Hosting.VirtualPathProvider#25](~/samples/snippets/csharp/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/CS/SamplePathProvider.cs#25)]
[!code-vb[System.Web.Hosting.VirtualPathProvider#25](~/samples/snippets/visualbasic/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/VB/SamplePathProvider.vb#25)]
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="CombineVirtualPaths">
<MemberSignature Language="C#" Value="public virtual string CombineVirtualPaths (string basePath, string relativePath);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance string CombineVirtualPaths(string basePath, string relativePath) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Hosting.VirtualPathProvider.CombineVirtualPaths(System.String,System.String)" />
<MemberSignature Language="VB.NET" Value="Public Overridable Function CombineVirtualPaths (basePath As String, relativePath As String) As String" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; virtual System::String ^ CombineVirtualPaths(System::String ^ basePath, System::String ^ relativePath);" />
<MemberSignature Language="F#" Value="abstract member CombineVirtualPaths : string * string -&gt; string&#xA;override this.CombineVirtualPaths : string * string -&gt; string" Usage="virtualPathProvider.CombineVirtualPaths (basePath, relativePath)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="basePath" Type="System.String" />
<Parameter Name="relativePath" Type="System.String" />
</Parameters>
<Docs>
<param name="basePath">The base path for the application.</param>
<param name="relativePath">The path to the virtual resource, relative to the base path.</param>
<summary>Combines a base path with a relative path to return a complete path to a virtual resource.</summary>
<returns>The complete path to a virtual resource.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Use the <xref:System.Web.Hosting.VirtualPathProvider.CombineVirtualPaths%2A> method to inspect the contents of a relative path to a virtual resource and perform any modifications required.
The default implementation combines the `basePath` and `relativePath` parameters according to standard ASP.NET path processing.
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>If you override the default implementation of the <see cref="M:System.Web.Hosting.VirtualPathProvider.CombineVirtualPaths(System.String,System.String)" /> method, you are required to convert any special syntax with the <paramref name="relativePath" /> parameter to a valid virtual path. You are responsible for syntax checking, path validation, and handling malformed input, as well as edge cases for well-formed input.
In most cases it will not be necessary to override the default <see cref="M:System.Web.Hosting.VirtualPathProvider.CombineVirtualPaths(System.String,System.String)" /> method. However, if you do need to modify the path, we recommend that you limit your <see cref="M:System.Web.Hosting.VirtualPathProvider.CombineVirtualPaths(System.String,System.String)" /> implementation to modifying tokens specific to your virtual path provider in the <paramref name="relativeUrl" /> parameter, and that you then call the base implementation to perform normal ASP.NET path processing</para>
</block>
</Docs>
</Member>
<Member MemberName="DirectoryExists">
<MemberSignature Language="C#" Value="public virtual bool DirectoryExists (string virtualDir);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance bool DirectoryExists(string virtualDir) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Hosting.VirtualPathProvider.DirectoryExists(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Overridable Function DirectoryExists (virtualDir As String) As Boolean" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; virtual bool DirectoryExists(System::String ^ virtualDir);" />
<MemberSignature Language="F#" Value="abstract member DirectoryExists : string -&gt; bool&#xA;override this.DirectoryExists : string -&gt; bool" Usage="virtualPathProvider.DirectoryExists virtualDir" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="virtualDir" Type="System.String" />
</Parameters>
<Docs>
<param name="virtualDir">The path to the virtual directory.</param>
<summary>Gets a value that indicates whether a directory exists in the virtual file system.</summary>
<returns>
<see langword="true" /> if the directory exists in the virtual file system; otherwise, <see langword="false" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Override the <xref:System.Web.Hosting.VirtualPathProvider.DirectoryExists%2A> method to indicate to the compilation system that the resource represented by `virtualDir` exists in the virtual file system provided by this <xref:System.Web.Hosting.VirtualPathProvider> instance.
If your custom <xref:System.Web.Hosting.VirtualPathProvider> class does not support directories, the <xref:System.Web.Hosting.VirtualPathProvider.DirectoryExists%2A> method should return `false`.
> [!NOTE]
> If your virtual file system will contain themes for the Web site (by creating a virtual `App_Themes` directory), your custom <xref:System.Web.Hosting.VirtualPathProvider> class must support directories.
## Examples
The following code example is an implementation of the <xref:System.Web.Hosting.VirtualPathProvider.DirectoryExists%2A> method in a custom <xref:System.Web.Hosting.VirtualPathProvider> class. For the full code required to run the example, see the Example section of the <xref:System.Web.Hosting.VirtualPathProvider> class overview topic.
[!code-csharp[System.Web.Hosting.VirtualPathProvider#22](~/samples/snippets/csharp/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/CS/SamplePathProvider.cs#22)]
[!code-vb[System.Web.Hosting.VirtualPathProvider#22](~/samples/snippets/visualbasic/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/VB/SamplePathProvider.vb#22)]
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="FileExists">
<MemberSignature Language="C#" Value="public virtual bool FileExists (string virtualPath);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance bool FileExists(string virtualPath) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Hosting.VirtualPathProvider.FileExists(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Overridable Function FileExists (virtualPath As String) As Boolean" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; virtual bool FileExists(System::String ^ virtualPath);" />
<MemberSignature Language="F#" Value="abstract member FileExists : string -&gt; bool&#xA;override this.FileExists : string -&gt; bool" Usage="virtualPathProvider.FileExists virtualPath" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="virtualPath" Type="System.String" />
</Parameters>
<Docs>
<param name="virtualPath">The path to the virtual file.</param>
<summary>Gets a value that indicates whether a file exists in the virtual file system.</summary>
<returns>
<see langword="true" /> if the file exists in the virtual file system; otherwise, <see langword="false" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Override the <xref:System.Web.Hosting.VirtualPathProvider.FileExists%2A> method to indicate to the compilation system that the resource represented by `virtualPath` exists in the virtual file system provided by this <xref:System.Web.Hosting.VirtualPathProvider> instance.
## Examples
The following code example is an implementation of the <xref:System.Web.Hosting.VirtualPathProvider.FileExists%2A> method in a custom <xref:System.Web.Hosting.VirtualPathProvider> class. For the full code required to run the example, see the Example section of the <xref:System.Web.Hosting.VirtualPathProvider> class overview topic.
[!code-csharp[System.Web.Hosting.VirtualPathProvider#21](~/samples/snippets/csharp/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/CS/SamplePathProvider.cs#21)]
[!code-vb[System.Web.Hosting.VirtualPathProvider#21](~/samples/snippets/visualbasic/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/VB/SamplePathProvider.vb#21)]
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="GetCacheDependency">
<MemberSignature Language="C#" Value="public virtual System.Web.Caching.CacheDependency GetCacheDependency (string virtualPath, System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance class System.Web.Caching.CacheDependency GetCacheDependency(string virtualPath, class System.Collections.IEnumerable virtualPathDependencies, valuetype System.DateTime utcStart) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Hosting.VirtualPathProvider.GetCacheDependency(System.String,System.Collections.IEnumerable,System.DateTime)" />
<MemberSignature Language="VB.NET" Value="Public Overridable Function GetCacheDependency (virtualPath As String, virtualPathDependencies As IEnumerable, utcStart As DateTime) As CacheDependency" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; virtual System::Web::Caching::CacheDependency ^ GetCacheDependency(System::String ^ virtualPath, System::Collections::IEnumerable ^ virtualPathDependencies, DateTime utcStart);" />
<MemberSignature Language="F#" Value="abstract member GetCacheDependency : string * System.Collections.IEnumerable * DateTime -&gt; System.Web.Caching.CacheDependency&#xA;override this.GetCacheDependency : string * System.Collections.IEnumerable * DateTime -&gt; System.Web.Caching.CacheDependency" Usage="virtualPathProvider.GetCacheDependency (virtualPath, virtualPathDependencies, utcStart)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Web.Caching.CacheDependency</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="virtualPath" Type="System.String" />
<Parameter Name="virtualPathDependencies" Type="System.Collections.IEnumerable" />
<Parameter Name="utcStart" Type="System.DateTime" />
</Parameters>
<Docs>
<param name="virtualPath">The path to the primary virtual resource.</param>
<param name="virtualPathDependencies">An array of paths to other resources required by the primary virtual resource.</param>
<param name="utcStart">The UTC time at which the virtual resources were read.</param>
<summary>Creates a cache dependency based on the specified virtual paths.</summary>
<returns>A <see cref="T:System.Web.Caching.CacheDependency" /> object for the specified virtual resources.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The default implementation of the <xref:System.Web.Hosting.VirtualPathProvider.GetCacheDependency%2A> method returns `null`. To cache virtual resources for later use you must override either the <xref:System.Web.Hosting.VirtualPathProvider.GetCacheDependency%2A> method or the <xref:System.Web.Hosting.VirtualPathProvider.GetFileHash%2A> method.
## Examples
The following code example implements the <xref:System.Web.Hosting.VirtualPathProvider.GetCacheDependency%2A> method for a custom <xref:System.Web.Hosting.VirtualPathProvider> class. For the full code required to run the example, see the Example section of the <xref:System.Web.Hosting.VirtualPathProvider> class overview topic.
[!code-csharp[System.Web.Hosting.VirtualPathProvider#28](~/samples/snippets/csharp/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/CS/SamplePathProvider.cs#28)]
[!code-vb[System.Web.Hosting.VirtualPathProvider#28](~/samples/snippets/visualbasic/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/VB/SamplePathProvider.vb#28)]
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="GetCacheKey">
<MemberSignature Language="C#" Value="public virtual string GetCacheKey (string virtualPath);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance string GetCacheKey(string virtualPath) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Hosting.VirtualPathProvider.GetCacheKey(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Overridable Function GetCacheKey (virtualPath As String) As String" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; virtual System::String ^ GetCacheKey(System::String ^ virtualPath);" />
<MemberSignature Language="F#" Value="abstract member GetCacheKey : string -&gt; string&#xA;override this.GetCacheKey : string -&gt; string" Usage="virtualPathProvider.GetCacheKey virtualPath" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="virtualPath" Type="System.String" />
</Parameters>
<Docs>
<param name="virtualPath">The path to the virtual resource.</param>
<summary>Returns a cache key to use for the specified virtual path.</summary>
<returns>A cache key for the specified virtual resource.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Use the <xref:System.Web.Hosting.VirtualPathProvider.GetCacheKey%2A> method to provide a custom cache key for virtual resources. If you do not override the <xref:System.Web.Hosting.VirtualPathProvider.GetCacheKey%2A> method, the virtual path is used for the cache key.
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>Only override the default <see cref="M:System.Web.Hosting.VirtualPathProvider.GetCacheKey(System.String)" /> method if creating a cache key based on the virtual path will not work for your application.</para>
</block>
</Docs>
</Member>
<Member MemberName="GetDirectory">
<MemberSignature Language="C#" Value="public virtual System.Web.Hosting.VirtualDirectory GetDirectory (string virtualDir);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance class System.Web.Hosting.VirtualDirectory GetDirectory(string virtualDir) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Hosting.VirtualPathProvider.GetDirectory(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Overridable Function GetDirectory (virtualDir As String) As VirtualDirectory" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; virtual System::Web::Hosting::VirtualDirectory ^ GetDirectory(System::String ^ virtualDir);" />
<MemberSignature Language="F#" Value="abstract member GetDirectory : string -&gt; System.Web.Hosting.VirtualDirectory&#xA;override this.GetDirectory : string -&gt; System.Web.Hosting.VirtualDirectory" Usage="virtualPathProvider.GetDirectory virtualDir" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Web.Hosting.VirtualDirectory</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="virtualDir" Type="System.String" />
</Parameters>
<Docs>
<param name="virtualDir">The path to the virtual directory.</param>
<summary>Gets a virtual directory from the virtual file system.</summary>
<returns>A descendent of the <see cref="T:System.Web.Hosting.VirtualDirectory" /> class that represents a directory in the virtual file system.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Hosting.VirtualPathProvider.GetDirectory%2A> method returns a descendent of the <xref:System.Web.Hosting.VirtualDirectory> class that contains the file and directories contained in the directory specified in the `virtualDir` parameter.
If your custom <xref:System.Web.Hosting.VirtualPathProvider> class does not support directories, the <xref:System.Web.Hosting.VirtualPathProvider.GetDirectory%2A> method should return `null`.
> [!NOTE]
> If your virtual file system will contain themes for the Web site (by creating a virtual `App_Themes` directory), your custom <xref:System.Web.Hosting.VirtualPathProvider> class must support directories.
## Examples
The following code example is an implementation of the <xref:System.Web.Hosting.VirtualPathProvider.GetDirectory%2A> method in a custom <xref:System.Web.Hosting.VirtualPathProvider> class. For the full code required to run the example, see the Example section of the <xref:System.Web.Hosting.VirtualPathProvider> class overview topic.
[!code-csharp[System.Web.Hosting.VirtualPathProvider#24](~/samples/snippets/csharp/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/CS/SamplePathProvider.cs#24)]
[!code-vb[System.Web.Hosting.VirtualPathProvider#24](~/samples/snippets/visualbasic/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/VB/SamplePathProvider.vb#24)]
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="GetFile">
<MemberSignature Language="C#" Value="public virtual System.Web.Hosting.VirtualFile GetFile (string virtualPath);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance class System.Web.Hosting.VirtualFile GetFile(string virtualPath) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Hosting.VirtualPathProvider.GetFile(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Overridable Function GetFile (virtualPath As String) As VirtualFile" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; virtual System::Web::Hosting::VirtualFile ^ GetFile(System::String ^ virtualPath);" />
<MemberSignature Language="F#" Value="abstract member GetFile : string -&gt; System.Web.Hosting.VirtualFile&#xA;override this.GetFile : string -&gt; System.Web.Hosting.VirtualFile" Usage="virtualPathProvider.GetFile virtualPath" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Web.Hosting.VirtualFile</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="virtualPath" Type="System.String" />
</Parameters>
<Docs>
<param name="virtualPath">The path to the virtual file.</param>
<summary>Gets a virtual file from the virtual file system.</summary>
<returns>A descendent of the <see cref="T:System.Web.Hosting.VirtualFile" /> class that represents a file in the virtual file system.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Hosting.VirtualPathProvider.GetFile%2A> method returns a descendent of the <xref:System.Web.Hosting.VirtualFile> class that represents the file specified by the `virtualPath` parameter.
## Examples
The following code example is an implementation of the <xref:System.Web.Hosting.VirtualPathProvider.GetFile%2A> method in a custom <xref:System.Web.Hosting.VirtualPathProvider> class. For the full code required to run the example, see the Example section of the <xref:System.Web.Hosting.VirtualPathProvider> class overview topic.
[!code-csharp[System.Web.Hosting.VirtualPathProvider#23](~/samples/snippets/csharp/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/CS/SamplePathProvider.cs#23)]
[!code-vb[System.Web.Hosting.VirtualPathProvider#23](~/samples/snippets/visualbasic/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/VB/SamplePathProvider.vb#23)]
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="GetFileHash">
<MemberSignature Language="C#" Value="public virtual string GetFileHash (string virtualPath, System.Collections.IEnumerable virtualPathDependencies);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance string GetFileHash(string virtualPath, class System.Collections.IEnumerable virtualPathDependencies) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Hosting.VirtualPathProvider.GetFileHash(System.String,System.Collections.IEnumerable)" />
<MemberSignature Language="VB.NET" Value="Public Overridable Function GetFileHash (virtualPath As String, virtualPathDependencies As IEnumerable) As String" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; virtual System::String ^ GetFileHash(System::String ^ virtualPath, System::Collections::IEnumerable ^ virtualPathDependencies);" />
<MemberSignature Language="F#" Value="abstract member GetFileHash : string * System.Collections.IEnumerable -&gt; string&#xA;override this.GetFileHash : string * System.Collections.IEnumerable -&gt; string" Usage="virtualPathProvider.GetFileHash (virtualPath, virtualPathDependencies)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="virtualPath" Type="System.String" />
<Parameter Name="virtualPathDependencies" Type="System.Collections.IEnumerable" />
</Parameters>
<Docs>
<param name="virtualPath">The path to the primary virtual resource.</param>
<param name="virtualPathDependencies">An array of paths to other virtual resources required by the primary virtual resource.</param>
<summary>Returns a hash of the specified virtual paths.</summary>
<returns>A hash of the specified virtual paths.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Use the <xref:System.Web.Hosting.VirtualPathProvider.GetFileHash%2A> method to provide a hash of the dependencies for a virtual-file-system resource.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="Initialize">
<MemberSignature Language="C#" Value="protected virtual void Initialize ();" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig newslot virtual instance void Initialize() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Hosting.VirtualPathProvider.Initialize" />
<MemberSignature Language="VB.NET" Value="Protected Overridable Sub Initialize ()" />
<MemberSignature Language="C++ CLI" Value="protected:&#xA; virtual void Initialize();" />
<MemberSignature Language="F#" Value="abstract member Initialize : unit -&gt; unit&#xA;override this.Initialize : unit -&gt; unit" Usage="virtualPathProvider.Initialize " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Initializes the <see cref="T:System.Web.Hosting.VirtualPathProvider" /> instance.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Hosting.VirtualPathProvider.Initialize%2A> method is called after the provider is registered with the ASP.NET compilation system. The <xref:System.Web.Hosting.VirtualPathProvider.Initialize%2A> method is used to provide any initialization required after the <xref:System.Web.Hosting.VirtualPathProvider> instance is placed into the environment the application occupies.
## Examples
The following code example is an implementation of the <xref:System.Web.Hosting.VirtualPathProvider.Initialize%2A> method that sets the path to a data file from the application's <xref:System.Web.Hosting.HostingEnvironment> instance. For the full code required to run the example, see the Example section of the <xref:System.Web.Hosting.VirtualPathProvider> class overview topic.
[!code-csharp[System.Web.Hosting.VirtualPathProvider#26](~/samples/snippets/csharp/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/CS/SamplePathProvider.cs#26)]
[!code-vb[System.Web.Hosting.VirtualPathProvider#26](~/samples/snippets/visualbasic/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/VB/SamplePathProvider.vb#26)]
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="InitializeLifetimeService">
<MemberSignature Language="C#" Value="public override object InitializeLifetimeService ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance object InitializeLifetimeService() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Hosting.VirtualPathProvider.InitializeLifetimeService" />
<MemberSignature Language="VB.NET" Value="Public Overrides Function InitializeLifetimeService () As Object" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; override System::Object ^ InitializeLifetimeService();" />
<MemberSignature Language="F#" Value="override this.InitializeLifetimeService : unit -&gt; obj" Usage="virtualPathProvider.InitializeLifetimeService " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Object</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Gives the <see cref="T:System.Web.Hosting.VirtualPathProvider" /> object an infinite lifetime by preventing a lease from being created.</summary>
<returns>Always <see langword="null" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This method overrides the <xref:System.MarshalByRefObject.InitializeLifetimeService%2A> method in its base class. It always returns `null` and thereby prevents a lease from being created that would limit the <xref:System.Web.Hosting.VirtualPathProvider> object's lifetime.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="OpenFile">
<MemberSignature Language="C#" Value="public static System.IO.Stream OpenFile (string virtualPath);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig class System.IO.Stream OpenFile(string virtualPath) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.Hosting.VirtualPathProvider.OpenFile(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Shared Function OpenFile (virtualPath As String) As Stream" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; static System::IO::Stream ^ OpenFile(System::String ^ virtualPath);" />
<MemberSignature Language="F#" Value="static member OpenFile : string -&gt; System.IO.Stream" Usage="System.Web.Hosting.VirtualPathProvider.OpenFile virtualPath" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.IO.Stream</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="virtualPath" Type="System.String" />
</Parameters>
<Docs>
<param name="virtualPath">The path to the virtual file.</param>
<summary>Returns a stream from a virtual file.</summary>
<returns>A read-only <see cref="T:System.IO.Stream" /> object for the specified virtual file or resource.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.Hosting.VirtualPathProvider.OpenFile%2A> method is a convenience method that enables you to get a stream from a virtual file without creating a <xref:System.Web.Hosting.VirtualPathProvider> instance.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="Previous">
<MemberSignature Language="C#" Value="protected internal System.Web.Hosting.VirtualPathProvider Previous { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance class System.Web.Hosting.VirtualPathProvider Previous" />
<MemberSignature Language="DocId" Value="P:System.Web.Hosting.VirtualPathProvider.Previous" />
<MemberSignature Language="VB.NET" Value="Protected Friend ReadOnly Property Previous As VirtualPathProvider" />
<MemberSignature Language="C++ CLI" Value="protected public:&#xA; property System::Web::Hosting::VirtualPathProvider ^ Previous { System::Web::Hosting::VirtualPathProvider ^ get(); };" />
<MemberSignature Language="F#" Value="member this.Previous : System.Web.Hosting.VirtualPathProvider" Usage="System.Web.Hosting.VirtualPathProvider.Previous" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName>get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Web.Hosting.VirtualPathProvider</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets a reference to a previously registered <see cref="T:System.Web.Hosting.VirtualPathProvider" /> object in the compilation system.</summary>
<value>The next <see cref="T:System.Web.Hosting.VirtualPathProvider" /> object in the compilation system.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
When a <xref:System.Web.Hosting.VirtualPathProvider> object is registered with the ASP.NET compilation system, it is added to a chain of providers. Use the <xref:System.Web.Hosting.VirtualPathProvider.Previous%2A> property to hand processing off to the previous <xref:System.Web.Hosting.VirtualPathProvider> object in the chain if the requested path is not provided by this <xref:System.Web.Hosting.VirtualPathProvider> instance.
The chain of path providers always ends with the default ASP.NET provider, which serves files from the file system.
## Examples
The following code example is an implementation of the <xref:System.Web.Hosting.VirtualPathProvider.GetFile%2A> method. If the requested virtual directory does not begin with the string `"/vrdir"`, the method uses the <xref:System.Web.Hosting.VirtualPathProvider.Previous%2A> property to pass the request to the next <xref:System.Web.Hosting.VirtualPathProvider> object in the chain. For the full code required to run the example, see the Example section of the <xref:System.Web.Hosting.VirtualPathProvider> class overview topic.
[!code-csharp[System.Web.Hosting.VirtualPathProvider#23](~/samples/snippets/csharp/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/CS/SamplePathProvider.cs#23)]
[!code-vb[System.Web.Hosting.VirtualPathProvider#23](~/samples/snippets/visualbasic/VS_Snippets_WebNet/system.web.hosting.virtualpathprovider/VB/SamplePathProvider.vb#23)]
]]></format>
</remarks>
</Docs>
</Member>
</Members>
</Type>
You can’t perform that action at this time.