[英]Create an application pool that uses .NET 4.0
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? 如何指定应用程序池应使用.NET Framework 4.0?
I see from the tags you're using IIS7. 我从标签上看到你正在使用IIS7。 Unless you absolutely have to, don't use the IIS6 compatibility components.
除非您绝对必须,否则请勿使用IIS6兼容性组件。 Your preferred approach should be to use the
Microsoft.Web.Administration
managed API. 您首选的方法应该是使用
Microsoft.Web.Administration
托管API。
To create an application pool using this and set the .NET Framework version to 4.0, do this: 要使用此方法创建应用程序池并将.NET Framework版本设置为4.0,请执行以下操作:
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: 您应该添加对
Microsoft.Web.Administration.dll
的引用,该引用可以在以下位置找到:
%SYSTEMROOT%\\System32\\InetSrv
newpool.Properties["ManagedRuntimeVersion"].Value = "v4.0";
Will do the same thing as the Microsoft.Web.Administration.dll but using DirectoryEntry 将与Microsoft.Web.Administration.dll做同样的事情,但使用DirectoryEntry
Also 也
newPool.InvokeSet("ManagedPipelineMode", new object[] { 0 });
Will switch to integrated or classic pipeline mode using DirectoryEntry. 将使用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 . 其他答案在您的特定情况下更好,但通常请记住,您可以使用appcmd工具执行此操作: https : //technet.microsoft.com/en-us/library/cc731784%28v=ws.10 %29.aspx 。 Specifically:
特别:
appcmd add apppool /name: string /managedRuntimeVersion: string /managedPipelineMode: Integrated | Classic
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.