我可以使用以下代码添加虚拟目录 使用Microsoft.web.administration;
app.VirtualDirectories.Add(“/ vDir”,“C:\ inetpub \ Ztet”);
并且代码可以工作,但是如何更新或更改此代码或使用代码删除它?假设我想更改虚拟目录名称或路径?
我试过
app.virtualDirectories.Remove(?? ===失败
也试图用。覆盖 app.VirtualDirectories.Add(“/ vDir”,“C:\ inetpub \ Xtet”); //使用不同的路径但是一旦它已经存在就失败
任何提示都会受到关注 还有关于如何为虚拟指挥分配或更改相关用户名和密码的任何想法吗?
答案 0 :(得分: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();
}
}