Create an application pool that uses .NET 4.0

最后都变了- 提交于 2019-12-02 20:18:29

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

Matt
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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!