【问题标题】:Changing IIS 6/7 Application Pool settings programmatically以编程方式更改 IIS 6/7 应用程序池设置
【发布时间】:2011-01-10 10:16:11
【问题描述】:

如何以编程方式更改 IIS 应用程序池的设置和属性(例如:Enable 32-Bit Applications 设置)?

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

【问题讨论】:

    标签: iis iis-7 iis-6 application-pool


    【解决方案1】:

    您可以使用 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

    【讨论】:

    • 谁知道你可以使用管道!?谢谢,太好了。
    【解决方案2】:

    试试this 的大小。

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

    【讨论】:

      【解决方案3】:

      对我有用的更简单的解决方案

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-01-22
        • 2013-10-12
        • 2019-03-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多