Изменение настроек пула приложений IIS 6/7 программным способом - PullRequest
6 голосов
/ 28 января 2010

Как программно изменить параметры и свойства пулов приложений IIS (например, параметр Enable 32-Bit Applications)?

Существуют ли справочные руководства по свойствам IIS 6 или 7 в MSDN или Technet?

Ответы [ 3 ]

8 голосов
/ 26 февраля 2010

Вы можете решить проблему, используя appcmd.exe.Где «DefaultAppPool» - это имя пула.

appcmd list apppool /xml "DefaultAppPool" | appcmd set apppool /in /enable32BitAppOnWin64:true

Если у вас возникли проблемы с запуском его с помощью C #, посмотрите Как выполнить командную строку в C # .

ps: дополнительную информацию о appcmd.exe вы можете найти здесь .Расположение инструмента по умолчанию: C: \ windows \ system32 \ inetsrv

1 голос
/ 28 января 2010

Попробуйте это для размера.

DirectoryEntry root = this.GetDirectoryEntry("IIS://" + this.DomainName + "/W3SVC/AppPools");
  if (root == null)
        return null;

List<ApplicationPool> Pools = new List<ApplicationPool>();
...
0 голосов
/ 05 мая 2017

Более простое решение, которое сработало для меня

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; }
}
...