如何以编程方式获取当前IIS应用程序池的名称,而不是ActiveDirectory

时间:2022-06-17 15:16:17

I am running into a situation with my Web API where the only option I can think of right now is to recycle the app pool while I dig through and find out the real cause of the problem. In the mean time I need a way to recycle the app pool after a condition is met. I thought I found the solution here: http://www.codeproject.com/Tips/780076/Recycle-Application-Pool-s-in-IIS-Server-Using-C

我正在使用我的Web API遇到这种情况,我现在唯一能想到的选择就是在我深入挖掘应用程序池时找出问题的真正原因。与此同时,我需要一种方法来满足条件后回收应用程序池。我以为我找到了解决方案:http://www.codeproject.com/Tips/780076/Recycle-Application-Pool-s-in-IIS-Server-Using-C

// Needs Microsoft.Web.Administration NuGet
public static void RecycleAppPool()
{
    ServerManager serverManager = new ServerManager();
    ApplicationPool appPool = serverManager.ApplicationPools["Test_AppPool"];

    if (appPool != null)
    {
        if (appPool.State == ObjectState.Stopped)
        {
            appPool.Start();
        }
        else
        {
            appPool.Recycle();
        }
    }
}

There are 2 problems with this:

这有两个问题:

1) I am getting an error when trying to run this code: "Filename: redirection.config Error: Cannot read configuration file due to insufficient permissions" I am getting this error in localhost, but I assume I'll also get it in my hosted Azure environment? Can I get around this?

1)我在尝试运行此代码时遇到错误:“文件名:redirection.config错误:由于权限不足而无法读取配置文件”我在localhost中收到此错误,但我想我也会在我的托管的Azure环境?我可以解决这个问题吗?

2) The second problem is I may not know what the name of the app pool is, so I need to figure that out programatically. I've found something like this:http://www.logue.com.ar/blog/2008/02/find-and-recycle-current-application-pool-programmatically-for-iis-6/ but that uses ActiveDirectory and I will not have the login details for the AD at my host... at least not that I know of... again this is hosted in an Azure Website.

2)第二个问题是我可能不知道应用程序池的名称是什么,所以我需要以编程方式解决这个问题。我发现了类似的内容:http://www.logue.com.ar/blog/2008/02/find-and-recycle-current-application-pool-programmatically-for-iis-6/但是它使用的是ActiveDirectory我将不会在我的主机上获得AD的登录详细信息...至少不是我知道...再次将其托管在Azure网站中。

So the question is, how do I get the name and of the current app pool in Azure and recycle it?

所以问题是,如何获取Azure中的名称和当前应用程序池并回收它?

As a side note, I'm doing this in my Global.asax in the Application_EndRequest after Flushing the current Response. Is there a better way?

作为旁注,我在刷新当前响应之后在Application_EndRequest中的Global.asax中执行此操作。有没有更好的办法?

1 个解决方案

#1


0  

So far the closest I could find is (found here: https://*.com/a/1081902/550975)

到目前为止,我能找到的最近的是(在这里找到:https://*.com/a/1081902/550975)

HttpRuntime.UnloadAppDomain();

which just restarts the app, not the app pool. This may however serve my purposes... we'll see. I'm still hoping someone has the actual answer, and I will mark it as the Accepted Answer if such a thing ever occurs.

它只是重新启动应用程序,而不是应用程序池。然而,这可能符合我的目的......我们会看到。我仍然希望有人得到实际答案,如果发生这种情况,我会将其标记为已接受的答案。

#1


0  

So far the closest I could find is (found here: https://*.com/a/1081902/550975)

到目前为止,我能找到的最近的是(在这里找到:https://*.com/a/1081902/550975)

HttpRuntime.UnloadAppDomain();

which just restarts the app, not the app pool. This may however serve my purposes... we'll see. I'm still hoping someone has the actual answer, and I will mark it as the Accepted Answer if such a thing ever occurs.

它只是重新启动应用程序,而不是应用程序池。然而,这可能符合我的目的......我们会看到。我仍然希望有人得到实际答案,如果发生这种情况,我会将其标记为已接受的答案。