【问题标题】:How do I recycle an application pool in IIS 6 through ASP.Net and C#?如何通过 ASP.Net 和 C# 回收 IIS 6 中的应用程序池?
【发布时间】:2012-02-06 12:08:25
【问题描述】:

我有一个 IIS 6 服务器,我需要回收一个特定的应用程序池。我需要使用 C# 设计一个 ASP.NET 网页来执行此任务。

我该怎么做?

【问题讨论】:

    标签: c# asp.net asp.net-mvc iis iis-6


    【解决方案1】:

    只需制作一个单独的网页/网络应用程序并将其安装在针对另一个应用程序池的网络服务器上(不确定如果作为应用程序的同一页面运行并链接到您要回收的同一应用程序池它将如何工作)。

    然后按照此处的说明进行操作:https://stackoverflow.com/a/496357/559144

    【讨论】:

      【解决方案2】:

      您可以使用DirectoryEntry 类以编程方式回收给定名称的应用程序池:

      var path = "IIS://localhost/W3SVC/AppPools/MyAppPool";
      var appPool = new DirectoryEntry(path);
      appPool.Invoke("Recycle");
      

      【讨论】:

        【解决方案3】:

        以下应该(我无法证明这一点,因为代码已经有一段时间没有使用了)就足够了:

        using System;
        using System.Collections.Generic;
        using System.Web;
        using System.DirectoryServices;
        
        public static class ApplicationPoolRecycle
        {
            public static void RecycleCurrentApplicationPool()
            {
                string appPoolId = GetCurrentApplicationPoolId();
                RecycleApplicationPool(appPoolId);
            }
            private static string GetCurrentApplicationPoolId()
            {
                string virtualDirPath = AppDomain.CurrentDomain.FriendlyName;
                virtualDirPath = virtualDirPath.Substring(4);
                int index = virtualDirPath.Length + 1;
                index = virtualDirPath.LastIndexOf("-", index - 1, index - 1);
                index = virtualDirPath.LastIndexOf("-", index - 1, index - 1);
                virtualDirPath = "IIS://localhost/" + virtualDirPath.Remove(index);
                DirectoryEntry virtualDirEntry = new DirectoryEntry(virtualDirPath);
                return virtualDirEntry.Properties["AppPoolId"].Value.ToString();
            }
            private static void RecycleApplicationPool(string appPoolId)
            {
                string appPoolPath = "IIS://localhost/W3SVC/AppPools/" + appPoolId;
                DirectoryEntry appPoolEntry = new DirectoryEntry(appPoolPath);
                appPoolEntry.Invoke("Recycle");
            }
        }
        

        【讨论】:

        • 如何在 Aspx 表单中进行设计??
        • @Riyaju - 您只需要一个调用ApplicationPoolRecycle.RecycleCurrentApplicationPool() 的页面,或者作为调用页面的结果(即在Page_Load 中)或作为单击按钮的结果(即myButton_Click )
        【解决方案4】:

        我用这个方法。

        HttpRuntime.UnloadAppDomain()

        HttpRuntime.UnloadAppDomain Method (System.Web)

        【讨论】:

          猜你喜欢
          • 2011-09-20
          • 1970-01-01
          • 2012-08-22
          • 2012-04-16
          • 1970-01-01
          • 1970-01-01
          • 2011-01-12
          • 2011-03-10
          • 1970-01-01
          相关资源
          最近更新 更多