I use the following code to create a app pool:
var metabasePath = string.Format(@"IIS://{0}/W3SVC/AppPools", serverName);
DirectoryEntry newpool;
DirectoryEntry apppools = new DirectoryEntry(metabasePath);
newpool = apppools.Children.Add(appPoolName, "IIsApplicationPool");
newpool.CommitChanges();
How do I specify that the app pool should use .NET Framework 4.0?
I see from the tags you’re using IIS7. Unless you absolutely have to, don’t use the IIS6 compatibility components. Your preferred approach should be to use the
Microsoft.Web.Administrationmanaged API.To create an application pool using this and set the .NET Framework version to 4.0, do this:
You should add a reference to
Microsoft.Web.Administration.dllwhich can be found in: