0

我可以使用 Microsoft.web.administration 添加具有以下代码的虚拟目录;

app.VirtualDirectories.Add("/vDir", "C:\inetpub\Ztet");

并且代码可以工作,但是我该如何更新或更改此代码或使用代码删除它?假设我想更改虚拟目录名称或路径?

我试过了

app.virtualDirectories.Remove(?? ===失败

还试图用 app.VirtualDirectories.Add("/vDir", "C:\inetpub\Xtet"); //具有不同的路径,但一旦它已经存在就会失败

关于如何为虚拟目录分配或更改关联的用户名和密码的任何提示都将得到应用?

4

1 回答 1

5

以下是一些示例:

        static void Main(string[] args)
    {
        CreateApp();

        RenameApp();

        EditApp();

        DeleteApp();
    }

    private static void EditApp()
    {
        using (ServerManager mgr = new ServerManager())
        {
            Application app = mgr.Sites["Default Web Site"].Applications["/TestAppNew"];
            VirtualDirectory vdir = app.VirtualDirectories["/"];
            vdir.UserName = "SomeUser";
            vdir.Password = "SomePassword";
            mgr.CommitChanges();
        }
    }

    private static void DeleteApp()
    {
        using (ServerManager mgr = new ServerManager())
        {

            Application app = mgr.Sites["Default Web Site"].Applications["/TestAppNew"];
            mgr.Sites["Default Web Site"].Applications.Remove(app);
            mgr.CommitChanges();
        }
    }

    private static void RenameApp()
    {
        using (ServerManager mgr = new ServerManager())
        {

            Application app = mgr.Sites["Default Web Site"].Applications["/TestApp"];
            app.Path = "/TestAppNew";

            mgr.CommitChanges();
        }
    }

    private static void CreateApp()
    {
        using (ServerManager mgr = new ServerManager())
        {

            mgr.Sites["Default Web Site"].Applications.Add("/TestApp", @"c:\inetpub\wwwroot");

            mgr.CommitChanges();
        }
    }
于 2013-08-21T21:27:23.110 回答