(使用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()
答案 0 :(得分: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;
}
}
}