【问题标题】:How to Delete a Virtual Directory from an FTP Site in IIS 7 and IIS 7.5 using C#/VB.Net and WMI?如何使用 C#/VB.Net 和 WMI 从 IIS 7 和 IIS 7.5 中的 FTP 站点删除虚拟目录?
【发布时间】:2011-02-22 15:48:50
【问题描述】:

我希望每个人都做得很好。

我尝试使用 WMi(服务器管理器类)删除虚拟目录并使用不同的值重新创建。 我面临的问题是虚拟目录没有被删除。请帮忙。

如何检查虚拟目录的存在和调用删除?

同样如何检查一个目录是否存在,然后再次添加相同的目录,但属性略有不同。

基本上,目标是重命名一个 虚拟目录以及重命名 一个网站。我希望我清楚

这是我的代码。

Try
  Using mgr As New ServerManager()
    Dim site As Site = mgr.Sites(DomainName)
    Dim app As Application = site.Applications("/") '.CreateElement() '("/" & VirDirName)
    Dim VirDir As VirtualDirectory = app.VirtualDirectories.CreateElement()
         For Each VirDir In app.VirtualDirectories
              If VirDir("path") = "/" & VirDirName Then
                    app.VirtualDirectories.Remove(VirDir)
                    Exit For
              End If
         Next
         mgr.CommitChanges()
  End Using
 Catch Err As Exception
      Ex = Err
      Throw New Exception(Err.Message, Ex)
 End Try

【问题讨论】:

    标签: vb.net iis-7 directory wmi virtual


    【解决方案1】:

    只是为了澄清上面的代码不是使用 WMI,而是使用 Microsoft.Web.Administration (MWA)。

    您是说您的目标是重命名站点的目录还是仅重命名站点名称?如果您更改站点名称,则无需进一步。如果目标是保持目录名称同步,那么几乎总是要重命名站点的根目录,所以只需执行以下操作:

    Using mgr As New ServerManager() 
       Dim site As Site = mgr.Sites(DomainName) 
       site.Applications("/").VirtualDirectories("/").PhysicalPath = "...Whatever new physical Path"
    
       mgr.CommitChanges()
    End Using 
    

    【讨论】:

    • 其实我想要别的东西,但你的解决方案无论如何都能解决问题。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-04
    • 2011-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多