简体   繁体   English

创建使用.NET 4.0的应用程序池

[英]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.

相关问题 正确退出使用 .NET 4.0 任务的 .net 控制台应用程序 - Properly exiting a .net console application that uses .NET 4.0 Tasks 我可以托管带有.NET 4.0应用程序池的.NET 2.0运行Web应用程序吗 - Can I Host .NET 2.0 Running Web Application with .NET 4.0 App Pool “Hello world”应用程序在.NET4.0中使用4个线程,但在.NET2.0中使用3个线程 - “Hello world” application uses 4 threads in .NET4.0, but 3 in .NET2.0 部署.net 4.0应用程序 - Deploying a .net 4.0 application 以指定的.net版本以编程方式创建iis 6.0网站和应用程序池 - programatically create iis 6.0 website and application pool with specified .net version 应用程序池标识(.net Framework 4.0)提供响应超时异常,但网络服务(框架2.0)正常运行 - Application pool identity (.net framework 4.0) is giving response timeout exception but network service (frame work 2.0) is working OK 将.net 4.5应用程序降级到4.0 - downgrade .net 4.5 application to 4.0 在 .net 4.0 应用程序中引用 .net 2.0 程序集 - Referencing .net 2.0 assemblies in .net 4.0 application .NET 4.5到.NET 4.0上的WPF应用程序 - Wpf application on .NET 4.5 to .NET 4.0 asp.net 4.0:datagrid使用控件状态或视图状态 - asp.net 4.0: datagrid uses control state or view state
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM