VirtualDirectory.Create Method1

创建虚拟目录。

语法

objAppSrv.Get("VirtualDirectory").Create(  
   VirtualDirectoryPath,  
   ApplicationPath,  
   PhysicalPath,  
   SiteName  
);  
  
objAppSrv.Get("VirtualDirectory").Create(  
   VirtualDirectoryPath,  
   ApplicationPath,  
   PhysicalPath,  
   SiteName  
)  

参数设置

名称 描述
VirtualDirectoryPath 一个 string 值,其中包含虚拟目录路径(例如“/MyVDir”)。
ApplicationPath 一个 string 值,其中包含应用程序路径(例如“/MyApp”)。
PhysicalPath 一个可选 string 值,其中包含存储虚拟目录内容的文件目录的物理路径(例如“C:\inetpub\MyVDirFiles”)。 尽管此参数是可选的,但大多数实现都需要它。 注意:IIS 不检查指定物理目录的存在。 如果指定无效路径并尝试在 IIS 管理器中打开虚拟目录,则 IIS 管理器会显示错误消息“找不到路径 '<path>' 的一部分”。
SiteName 一个 string 值,该值包含虚拟目录的网站名称(例如“默认网站”)。

返回值

此方法不返回值。

注解

VirtualDirectory 对象继承自 ConfiguredObject 类;它不从 VirtualDirectoryElementDefaults 类继承。 这意味着 VirtualDirectoryElementDefaults 对象的属性也必须在 VirtualDirectory 对象上声明。

示例

以下示例在默认网站上的 MyApp 应用程序下创建一个名为 MyVDir 的虚拟目录。

' Connect to the WebAdministration namespace.  
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")  
  
' Define the parameters.  
strVDirPath = "/MyVDir"  
strAppPath = "/MyApp"  
strPhysicalPath = "C:\inetpub\MyVDirFiles"  
strSiteName = "Default Web Site"  
  
' Create the new virtual directory.  
oWebAdmin.Get("VirtualDirectory").Create _  
    strVDirPath, strAppPath, strPhysicalPath, strSiteName  

要求

类型 描述
客户端 - IIS 7.0(在 Windows Vista 上)
- IIS 7.5(在 Windows 7 上)
- IIS 8.0(在 Windows 8 上)
- IIS 10.0(在 Windows 10 上)
服务器 - IIS 7.0(在 Windows Server 2008 上)
- IIS 7.5(在 Windows Server 2008 R2 上)
- IIS 8.0(在 Windows Server 2012 上)
- IIS 8.5(在 Windows Server 2012 R2 上)
- IIS 10.0(在 Windows Server 2016 上)
产品 - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0
MOF 文件 WebAdministration.mof

另请参阅

VirtualDirectory 类
VirtualDirectoryContainsConfigurationSection 类