How can I programmatically change IIS application pools' settings and properties (for example: the Enable 32-Bit Applications
set开发者_如何学Pythonting)?
Are there reference guides on properties for IIS 6 or 7 on MSDN or Technet?
You can solve the problem using appcmd.exe. Where "DefaultAppPool" is the name of the pool.
appcmd list apppool /xml "DefaultAppPool" | appcmd set apppool /in /enable32BitAppOnWin64:true
If you have any troubles with running it using C# take a look How To: Execute command line in C#.
ps: Additional information about appcmd.exe you can find here. Default location of the tool is C:\windows\system32\inetsrv
Try this on for size.
DirectoryEntry root = this.GetDirectoryEntry("IIS://" + this.DomainName + "/W3SVC/AppPools");
if (root == null)
return null;
List<ApplicationPool> Pools = new List<ApplicationPool>();
...
An easier solution that worked for me
ServerManager server = new ServerManager();
ApplicationPoolCollection applicationPools = server.ApplicationPools;
//this is my object where I put default settings I need,
//not necessary but better approach
DefaultApplicationPoolSettings defaultSettings = new DefaultApplicationPoolSettings();
foreach (ApplicationPool pool in applicationPools)
{
try
{
if (pool.Name == <Your pool name here>)
{
pool.ManagedPipelineMode = defaultSettings.managedPipelineMode;
pool.ManagedRuntimeVersion = defaultSettings.managedRuntimeVersion;
pool.Enable32BitAppOnWin64 = defaultSettings.enable32BitApplications;
pool.ProcessModel.IdentityType = defaultSettings.IdentityType;
pool.ProcessModel.LoadUserProfile = defaultSettings.loadUserProfile;
//Do not forget to commit changes
server.CommitChanges();
}
}
catch (Exception ex)
{
// log
}
}
and my object for example purpose
public class DefaultApplicationPoolSettings
{
public DefaultApplicationPoolSettings()
{
managedPipelineMode = ManagedPipelineMode.Integrated;
managedRuntimeVersion = "v4.0";
enable32BitApplications = true;
IdentityType = ProcessModelIdentityType.LocalSystem;
loadUserProfile = true;
}
public ManagedPipelineMode managedPipelineMode { get; set; }
public string managedRuntimeVersion { get; set; }
public bool enable32BitApplications { get; set; }
public ProcessModelIdentityType IdentityType { get; set;}
public bool loadUserProfile { get; set; }
}
精彩评论