[英]Add Application Pool to iis C# using Microsoft.Web.Administration
I am trying to add Application Pool.我正在尝试添加应用程序池。 My code:
我的代码:
ServerManager iis = new ServerManager();
iis.ApplicationPools.Add(new ApplicationPool() {Name= "My Pool",
AutoStart=true,ManagedRuntimeVersion="v4.0", ManagedPipelineMode=ManagedPipelineMode.Integrated });
Problem is I cant create object ApplicationPool.问题是我无法创建 object ApplicationPool。 The reason is probably that the class it inherits has a protected internal constructor.
原因可能是它继承的 class 有一个受保护的内部构造函数。 And the error is displayed that there is no such overload of the constructor for this class.
并显示此 class 的构造函数没有此类重载的错误。
But I think I should be able to create an object of this class somehow, because the Add method accepts this type of object.但我想我应该能够以某种方式创建这个 class 的 object,因为 Add 方法接受这种类型的 object。 It has a second overload where it accepts a string.
它有第二个重载,它接受一个字符串。
Edit:编辑:
It works but I don't want to do it this way它有效,但我不想这样做
iis.ApplicationPools.Add("My poll");
foreach (ApplicationPool item in applicationPool)
{
if (item.Name == "My poll")
{
item.AutoStart = true;
item.ManagedRuntimeVersion = "v4.0";
item.ManagedPipelineMode = ManagedPipelineMode.Integrated;
iis.CommitChanges();
}
}
I find this:我发现这个:
var item = iis.ApplicationPools.Add("My poll");
item.AutoStart = true;
item.ManagedRuntimeVersion = "v4.0";
item.ManagedPipelineMode = ManagedPipelineMode.Integrated;
item.Enable32BitAppOnWin64 = true;
You could try to use the below code;您可以尝试使用以下代码;
using System;
using System.Text;
using Microsoft.Web.Administration;
internal static class Sample {
private static void Main() {
using(ServerManager serverManager = new ServerManager()) {
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection applicationPoolsSection = config.GetSection("system.applicationHost/applicationPools");
ConfigurationElementCollection applicationPoolsCollection = applicationPoolsSection.GetCollection();
ConfigurationElement addElement = applicationPoolsCollection.CreateElement("add");
addElement["name"] = @"pool1";
addElement["managedRuntimeVersion"] = @"v4.0";
applicationPoolsCollection.Add(addElement);
serverManager.CommitChanges();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.