如何更改IIS应用程序池seetings / properties programmatic(C#)? 例如,如何更改“启用32位应用程序”设置? 在MSDN或Technet上是否有IIS 6和IIS 7的属性引用? 在此先感谢您的帮助 !
答案 0 :(得分:8)
您可以使用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的其他信息here。该工具的默认位置是C:\ windows \ system32 \ inetsrv
答案 1 :(得分:1)
尝试使用this尺寸。
DirectoryEntry root = this.GetDirectoryEntry("IIS://" + this.DomainName + "/W3SVC/AppPools");
if (root == null)
return null;
List<ApplicationPool> Pools = new List<ApplicationPool>();
...
答案 2 :(得分:0)
一个对我有用的简单解决方案
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; }
}