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

发布于 2025-01-03 01:09:29 字数 82 浏览 1 评论 0原文

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

我该怎么做?

I have an IIS 6 server and I need to recycle a specific application pool. I need to design an ASP.NET web page using C# that performs this task.

How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

冷心人i 2025-01-10 01:09:29

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

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

just make a separated web page / web application and install it on the web server targeting another app pool (not sure how it would work if running as same page of your app and being linked to the same app pool you want to recycle).

then follow instructions here: https://stackoverflow.com/a/496357/559144

超可爱的懒熊 2025-01-10 01:09:29

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

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

You can use the DirectoryEntry class to programmatically recycle an application pool given its name:

var path = "IIS://localhost/W3SVC/AppPools/MyAppPool";
var appPool = new DirectoryEntry(path);
appPool.Invoke("Recycle");
你不是我要的菜∠ 2025-01-10 01:09:29

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

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

The following should (I can't attest to that as the code hasn't been used in quite some time) suffice:

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");
    }
}
雪若未夕 2025-01-10 01:09:29

我用的是这个方法。

HttpRuntime.UnloadAppDomain()

HttpRuntime.UnloadAppDomain 方法 (System.Web)

I using this method.

HttpRuntime.UnloadAppDomain()

HttpRuntime.UnloadAppDomain Method (System.Web)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文