我不确定复制方法,但您可以访问当前应用程序池的属性,然后创建一个具有相同属性的新应用程序池:
// How to access a specific app pool
DirectoryEntry appPools = new DirectoryEntry("IIS://" + serverName + "/w3svc/apppools", adminUsername, adminPassword);
foreach (DirectoryEntry AppPool in appPools.Children)
{
if (appPoolName.Equals(AppPool.Name, StringComparison.OrdinalIgnoreCase))
{
// access the properties of AppPool...
}
}
然后通过调用下面列出的方法在代码中创建一个新池:
CreateAppPool("IIS://Localhost/W3SVC/AppPools", "MyAppPool");
来自MSDN的应用程序池创建方法:
static void CreateAppPool(string metabasePath, string appPoolName)
{
// metabasePath is of the form "IIS://<servername>/W3SVC/AppPools"
// for example "IIS://localhost/W3SVC/AppPools"
// appPoolName is of the form "<name>", for example, "MyAppPool"
Console.WriteLine("\nCreating application pool named {0}/{1}:", metabasePath, appPoolName);
try
{
if (metabasePath.EndsWith("/W3SVC/AppPools"))
{
DirectoryEntry apppools = new DirectoryEntry(metabasePath);
DirectoryEntry newpool = apppools.Children.Add(appPoolName, "IIsApplicationPool");
newpool.CommitChanges();
}
else
{
Console.WriteLine(" Failed in CreateAppPool; application pools can only be created in the */W3SVC/AppPools node.");
}
}
catch (Exception ex)
{
Console.WriteLine("Failed in CreateAppPool with the following exception: \n{0}", ex.Message);
}
}