I am using the code below to create a new application pool in the Installer class of my application:
private static void CreateAppPool(string serverName, 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"
string metabasePath = string.Format("IIS://{0}/W3SVC/AppPools", serverName);
Console.WriteLine("\nCreating application pool named {0}/{1}:", metabasePath, appPoolName);
try
{
DirectoryEntry apppools = new DirectoryEntry(metabasePath);
DirectoryEntry newpool = apppools.Children.Add(appPoolName, "IIsApplicationPool");
newpool.CommitChanges();
Console.WriteLine("AppPool created.");
}
catch (Exception ex)
{
Console.WriteLine("Failed in CreateAppPool with the following exception: \n{0}", ex.Message);
}
}
How can I change the user credentials under which this application pool is running?