VirtualPathProvider.GetDirectory(String) 方法
定义
从虚拟文件系统中获取一个虚拟目录。Gets a virtual directory from the virtual file system.
public:
virtual System::Web::Hosting::VirtualDirectory ^ GetDirectory(System::String ^ virtualDir);
public virtual System.Web.Hosting.VirtualDirectory GetDirectory (string virtualDir);
abstract member GetDirectory : string -> System.Web.Hosting.VirtualDirectory
override this.GetDirectory : string -> System.Web.Hosting.VirtualDirectory
Public Overridable Function GetDirectory (virtualDir As String) As VirtualDirectory
参数
- virtualDir
- String
虚拟目录的路径。The path to the virtual directory.
返回
VirtualDirectory 类的子代,表示虚拟文件系统中的一个目录。A descendent of the VirtualDirectory class that represents a directory in the virtual file system.
示例
下面的代码示例是 GetDirectory 自定义类中方法的实现 VirtualPathProvider 。The following code example is an implementation of the GetDirectory method in a custom VirtualPathProvider class. 有关运行此示例所需的完整代码,请参阅类概述主题的 "示例" 部分 VirtualPathProvider 。For the full code required to run the example, see the Example section of the VirtualPathProvider class overview topic.
public override VirtualDirectory GetDirectory(string virtualDir)
{
if (IsPathVirtual(virtualDir))
return new SampleVirtualDirectory(virtualDir, this);
else
return Previous.GetDirectory(virtualDir);
}
Public Overrides Function GetDirectory(ByVal virtualDir As String) As VirtualDirectory
If (IsPathVirtual(virtualDir)) Then
Return New SampleVirtualDirectory(virtualDir, Me)
Else
Return Previous.GetDirectory(virtualDir)
End If
End Function
注解
GetDirectory方法返回 VirtualDirectory 类的子代,该类包含参数中指定的目录中包含的文件和目录 virtualDir 。The GetDirectory method returns a descendent of the VirtualDirectory class that contains the file and directories contained in the directory specified in the virtualDir parameter.
如果自定义 VirtualPathProvider 类不支持目录,则该 GetDirectory 方法应返回 null 。If your custom VirtualPathProvider class does not support directories, the GetDirectory method should return null.
备注
如果虚拟文件系统将包含网站 (通过创建虚拟目录) 的主题,则 App_Themes 您的自定义 VirtualPathProvider 类必须支持目录。If your virtual file system will contain themes for the Web site (by creating a virtual App_Themes directory), your custom VirtualPathProvider class must support directories.