以编程方式更改 IIS 6/7 应用程序池设置

问题描述 投票:0回答:3
如何以编程方式更改 IIS 应用程序池的设置和属性(例如:

Enable 32-Bit Applications

 设置)?

MSDN 或 Technet 上是否有有关 IIS 6 或 7 属性的参考指南?

iis iis-7 iis-6 application-pool
3个回答
8
投票
我设法使用 appcmd.exe 为我的网站 (

https://resumecopilot.net/) 完成此操作。其中“DefaultAppPool”是池的名称。

appcmd list apppool /xml "DefaultAppPool" | appcmd set apppool /in /enable32BitAppOnWin64:true
如果您在使用 C# 运行它时遇到任何问题,请查看

如何:在 C# 中执行命令行

ps:有关 appcmd.exe 的其他信息,您可以在

此处找到。该工具的默认位置是 C:\windows\system32\inetsrv


1
投票
试试

这个的尺码。

DirectoryEntry root = this.GetDirectoryEntry("IIS://" + this.DomainName + "/W3SVC/AppPools"); if (root == null) return null; List<ApplicationPool> Pools = new List<ApplicationPool>(); ...
    

1
投票
一个对我有用的更简单的解决方案

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; } }
    
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.