简体   繁体   English

使用 Microsoft.Web.Administration 将应用程序池添加到 iis C#

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

相关问题 如何使用Microsoft.Web.Administration添加子应用程序? - How to add child application using Microsoft.Web.Administration? 使用Microsoft.Web.Administration库创建IIS应用程序创建两个应用程序而不是一个 - IIS application creation by using Microsoft.Web.Administration library creates two application instead of one IIS-如何使用Microsoft.Web.Administration编辑应用程序的本地配置 - IIS - How to edit local config for application with Microsoft.Web.Administration 使用 Microsoft.Web.Administration 应用程序更改身份验证模式 - Using Microsoft.Web.Administration Application to change authentication mode 如何正确使用Microsoft.Web.Administration从网页启动应用程序池? - how to use Microsoft.Web.Administration properly to start an application pool from a web page? IIS:如何使用Microsoft.Web.Administration在网站中创建虚拟目录 - IIS: How to create virtualdirectory in website with Microsoft.Web.Administration IIS 8的Microsoft.Web.Administration不会显示所有站点 - Microsoft.Web.Administration for IIS 8 does not display all sites Microsoft.Web.Administration Ssl 证书未在 iis 管理器中选择 - Microsoft.Web.Administration Ssl cert not selected in iis manager 如何使用Microsoft.Web.Administration命名空间在IIS7中干净地操作Handler Mappings? - How do I manipulate Handler Mappings cleanly in IIS7 using the Microsoft.Web.Administration namespace? 使用模拟自动创建IIS7网站(使用Microsoft.Web.Administration) - Automating IIS7 Website creation using impersonation (with Microsoft.Web.Administration)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM