0

(使用 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()
4

1 回答 1

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;
}
}
}
于 2012-11-05T21:55:37.707 回答