Create an application pool that uses .NET 4.0

前端 未结 3 891
轮回少年
轮回少年 2021-02-01 17:43

I use the following code to create a app pool:

var metabasePath = string.Format(@\"IIS://{0}/W3SVC/AppPools\", serverName);
DirectoryEntry newpool;
DirectoryEntr         


        
3条回答
  •  醉梦人生
    2021-02-01 18:15

    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

提交回复
热议问题