0

(Using IronPython), I'm adding an application pool as follows, but the app pool won't show up in Internet Information Services (IIS) Manager.

Anyone know why this discrepancy is happening? This is working because I see the app pool I added when I look through the app pools (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()
Gezim
  • 7,112
  • 10
  • 62
  • 98

1 Answers1

1

Try this:

// 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(); 

It could happen because your not initiating the new ServerManager / Application-Pool. Then when it goes to create the user; it may not be an account that can actually create the user account. If You'd like to validate the application can indeed make those sort of changes also; you could use:

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;
}
}
}
Greg
  • 11,302
  • 2
  • 48
  • 79
  • I apologize; but I didn't notice you said Iron Python. That above code is in C# using Assembly: `using Microsoft.Web.Administration;` which can be found in `System32\inetsrv` folder. The other code; is within `using System.Security.Principal;` and `using System.Security.Identity;` I apologize. – Greg Dec 12 '12 at 19:03