重新启动(回收)的应用程序池重新启动、应用程序

2023-09-02 20:41:42 作者:捂着心脏说疼

我怎样才能重新启动(再循环)IIS应用程序池从C#(.NET 2)?

How can I restart(recycle) IIS Application Pool from C# (.net 2)?

鸭preciate如果您发布样本code?

Appreciate if you post sample code?

推荐答案

约翰,

如果您在 IIS7 ,那么这将做到这一点,如果它被停止。我想你可以调整重新启动,而不必被显示。

If you're on IIS7 then this will do it if it is stopped. I assume you can adjust for restarting without having to be shown.

// Gets the application pool collection from the server.
[ModuleServiceMethod(PassThrough = true)]
public ArrayList GetApplicationPoolCollection()
{
    // Use an ArrayList to transfer objects to the client.
    ArrayList arrayOfApplicationBags = new ArrayList();

    ServerManager serverManager = new ServerManager();
    ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;
    foreach (ApplicationPool applicationPool in applicationPoolCollection)
    {
        PropertyBag applicationPoolBag = new PropertyBag();
        applicationPoolBag[ServerManagerDemoGlobals.ApplicationPoolArray] = applicationPool;
        arrayOfApplicationBags.Add(applicationPoolBag);
        // If the applicationPool is stopped, restart it.
        if (applicationPool.State == ObjectState.Stopped)
        {
            applicationPool.Start();
        }

    }

    // CommitChanges to persist the changes to the ApplicationHost.config.
    serverManager.CommitChanges();
    return arrayOfApplicationBags;
}

如果您在 IIS6 我不敢肯定,但你可以尝试得到的web.config和编辑修改日期什么的。一旦一个编辑是向web.config中则应用程序将重新启动。

If you're on IIS6 I'm not so sure, but you could try getting the web.config and editing the modified date or something. Once an edit is made to the web.config then the application will restart.

 
精彩推荐
图片推荐