编程方式添加应用程序池(应用程序池)未显示在Internet Information Services(IIS)管理器了
问题描述:
(使用IronPython的),我添加一个应用程序池如下,但网络信息中的应用程序池将不会出现服务(IIS)管理器。编程方式添加应用程序池(应用程序池)未显示在Internet Information Services(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()
答
试试这个:
// 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的/应用程序池。然后当它创建用户时;它可能不是一个真正可以创建用户帐户的帐户。如果您想验证应用程序确实可以进行这些更改,你可以使用:
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;
}
}
}
我道歉;但我没有注意到你说Iron Python。上面的代码在C#中使用Assembly:'using Microsoft.Web.Administration;'可以在'System32 \ inetsrv'文件夹中找到。其他代码;在'使用System.Security.Principal;'和'使用System.Security.Identity;'我道歉。 – Greg 2012-12-12 19:03:08