Create an application pool that uses .NET 4.0

23,104

Solution 1

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.Administration managed API.

To create an application pool using this and set the .NET Framework version to 4.0, do this:

using Microsoft.Web.Administration;
...

using(ServerManager serverManager = new ServerManager())
{
  ApplicationPool newPool = serverManager.ApplicationPools.Add("MyNewPool");
  newPool.ManagedRuntimeVersion = "v4.0";
  serverManager.CommitChanges();
}

You should add a reference to Microsoft.Web.Administration.dll which can be found in:

%SYSTEMROOT%\System32\InetSrv

Solution 2

newpool.Properties["ManagedRuntimeVersion"].Value = "v4.0";

Will do the same thing as the Microsoft.Web.Administration.dll but using DirectoryEntry

Also

newPool.InvokeSet("ManagedPipelineMode", new object[] { 0 });

Will switch to integrated or classic pipeline mode using DirectoryEntry.

Solution 3

The other answers are better in your particular scenario, but in general keep in mind that you can use the appcmd tool to do this: https://technet.microsoft.com/en-us/library/cc731784%28v=ws.10%29.aspx. Specifically:

appcmd add apppool /name: string /managedRuntimeVersion: string /managedPipelineMode: Integrated | Classic

Share:
23,104
jgauffin
Author by

jgauffin

coderr.io Automated exception handling for .NET - Coderr finds more of your errors and let you solve them faster. (I'm one of the founders). https://coderr.io | https://github.com/coderrio/ About me Blog | CV | Twitter My open source projects: Griffin.Framework Business application library Griffin.Yo A SPA library/framework written in TypeScript MarkdownWeb Web application for writing developer documentation

Updated on July 09, 2022

Comments

  • jgauffin
    jgauffin almost 2 years

    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?