如何以编程方式更改 IIS 应用程序池的设置和属性(例如:Enable 32-Bit Applications
设置)?
MSDN 或 Technet 上是否有关于 IIS 6 或 7 属性的参考指南?
如何以编程方式更改 IIS 应用程序池的设置和属性(例如:Enable 32-Bit Applications
设置)?
MSDN 或 Technet 上是否有关于 IIS 6 或 7 属性的参考指南?
您可以使用 appcmd.exe 解决问题。其中“DefaultAppPool”是池的名称。
appcmd list apppool /xml "DefaultAppPool" | appcmd set apppool /in /enable32BitAppOnWin64:true
如果您在使用 C# 运行它时遇到任何问题,请查看How To: Execute command line in C#。
ps:有关 appcmd.exe 的其他信息,您可以在此处找到。该工具的默认位置是 C:\windows\system32\inetsrv
试穿这个尺寸。
DirectoryEntry root = this.GetDirectoryEntry("IIS://" + this.DomainName + "/W3SVC/AppPools");
if (root == null)
return null;
List<ApplicationPool> Pools = new List<ApplicationPool>();
...
一个对我有用的更简单的解决方案
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
}
}
和我的对象例如目的
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; }
}