【问题标题】:programmatically added application pool (app pool) is not showing up in Internet Information Services (IIS) Manager以编程方式添加的应用程序池(应用程序池)未显示在 Internet 信息服务 (IIS) 管理器中
【发布时间】:2012-07-19 17:12:54
【问题描述】:

(使用 IronPython),我正在添加一个应用程序池,如下所示,但应用程序池不会显示在 Internet 信息服务 (IIS) 管理器中。

有人知道为什么会出现这种差异吗?这是有效的,因为我在查看应用程序池 (serverManager.ApplicationPools) 时看到了我添加的应用程序池。

import clr
clr.AddReference("Microsoft.Web.Administration")

from Microsoft.Web.Administration import *
import getpass

current_user = System.Security.Principal.WindowsIdentity.GetCurrent().Name

serverManager = ServerManager()
app_pool = serverManager.ApplicationPools.Add("my pool name")
app_pool.AutoStart = True
app_pool.ManagedPipelineMode = ManagedPipelineMode.Integrated
app_pool.ManagedRuntimeVersion = "v2.0"
app_pool.ProcessModel.IdentityType =   ProcessModelIdentityType.SpecificUser
app_pool.ProcessModel.UserName = current_user
app_pool.ProcessModel.Password = getpass.getpass("Password:")

serverManager.CommitChanges()

【问题讨论】:

    标签: iis-7 application-pool


    【解决方案1】:

    试试这个:

    // Create the Server Manager Object:
    ServerManager defaultManager = new ServerManager();
    
    // Add the Application-Pool:
    ApplicationPool defaultAppPool = defaultManager.ApplicationPools.Add("DefaultAppPool");
    
    // Configure the Pool to Automatically Start.
    defaultAppPool.AutoStart = true;
    
    // If IIS Application-Pool Exceeds the CPU Limit Property:
    defaultAppPool.Cpu.Action = ProcessorAction.KillW3wp;
    
    // Pipeline:
    defaultAppPool.ManagedPipelineMode = ManagedPipeLineMode.Integrated;
    
    // Set Runtime:
    defaultAppPool.ManagedRuntimeVersion = "v2.0";
    
    // User Network Service Account:
    defaultAppPool.ProcessModel.IdentityType = ProcessModelIdentityType.NetworkService;
    
    // Idle:
    defaultAppPool.ProcessModel.IdleTimeout = TimeSpan.FromMinutes(5);
    
    // Max Number of IIS Worker Processes: (W3wp)
    defaultAppPool.ProcessModel.MaxProcess = 1;
    
    // Commit the Changes:
    defaultManager.CommitChanges();
    
    // Dispose:
    defaultManager.Dispose(); 
    

    这可能是因为您没有启动新的 ServerManager / Application-Pool。然后当它去创建用户时;它可能不是可以实际创建用户帐户的帐户。如果您想验证应用程序确实也可以进行此类更改;你可以使用:

    WindowsIdentity userIdentity = WindowsIdentity.GetCurrent();
    
    // Test Operating System Version Vista or Greater for UAC
    if (Environment.OSVersion.Platform != PlatformID.Win32NT || Environment.OSVersion.Version.Major < 6)
    {
    
    return false;
    
    }
    
    else
    {
    
    // If UserIdentity came back Null
    if (userIdentity == null)
    {
    
    throw new InvalidOperationException("Unable to get current user");
    
    }
    
    else 
    {
    // Set Security Principal to ensure user is in proper role.
    WindowsPrincipal userPolicy = new WindowsPrincipal(userIdentity);
    
    if (userPolicy.IsInRole(WindowsBuiltInRole.Administrator))
    { 
    return true;
    }
    else
    {
    MessageBox.Show("Application isn't in proper administrative user role; please restart.");
    return false;
    }
    }
    }
    

    【讨论】:

    • 我很抱歉;但我没注意到你说的是铁蟒。上面的代码在 C# 中使用 Assembly:using Microsoft.Web.Administration;,可以在 System32\inetsrv 文件夹中找到。另一个代码;在using System.Security.Principal;using System.Security.Identity; 之内,我很抱歉。
    猜你喜欢
    • 1970-01-01
    • 2012-05-19
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多