如何通过ASP.Net和C#回收IIS 6中的应用程序池?

如何通过ASP.Net和C#回收IIS 6中的应用程序池?,c#,asp.net,asp.net-mvc,iis,iis-6,C#,Asp.net,Asp.net Mvc,Iis,Iis 6,我有一个IIS 6服务器,我需要回收一个特定的应用程序池。我需要使用C#设计一个ASP.NET网页来执行此任务 如何执行此操作?您可以使用该类以编程方式回收名为的应用程序池: var path = "IIS://localhost/W3SVC/AppPools/MyAppPool"; var appPool = new DirectoryEntry(path); appPool.Invoke("Recycle"); 以下内容应该(我不能证明这一点,因为代码已经有一段时间没有被使用了)足够了:

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

如何执行此操作?

您可以使用该类以编程方式回收名为的应用程序池:

var path = "IIS://localhost/W3SVC/AppPools/MyAppPool";
var appPool = new DirectoryEntry(path);
appPool.Invoke("Recycle");
以下内容应该(我不能证明这一点,因为代码已经有一段时间没有被使用了)足够了:


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

然后按照此处的说明操作:

I使用此方法

HttpRuntime.UnloadAppDomain()


我如何在Aspx表单中进行设计???@Riyaju-您只需要调用
ApplicationPoolRecycle.RecycleCurrentApplicationPool()
的页面,无论是调用页面(即在
page\u Load
)还是单击按钮(即
myButton\u单击
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");
    }
}