Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create an application pool that uses .NET 4.0

Tags:

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?

like image 884
jgauffin Avatar asked Jan 25 '11 09:01

jgauffin


People also ask

How do I add .NET to application pool?

In the Add Application Pool dialog box, enter the name of the application pool in the Name: box, in the . NET Framework version: drop-down list select the . NET Framework version your site or application uses, in the Managed pipeline mode: drop-down list select Integrated or Classic, and then click OK.


2 Answers

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

like image 169
Kev Avatar answered Sep 17 '22 13:09

Kev


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.

like image 42
Matt Avatar answered Sep 18 '22 13:09

Matt