d sharpe
d sharpe

Reputation: 189

How can I detect an IIS Application Pool startup

Is there a way of detecting when an IIS (6 or 7.0) Application Pool starts up (or indeed shuts down) or is manually recycled via IIS Manager ?

This isn't required in II7.5 due to its Application Initialisation module.

But I need to know if an application pool shuts down, so i can restart it. and when it starts up do a warmup on the web application on that pool.

I wondered if it would be possible to watch for events in the server log using the scheduler, but I cant locate log entries when the app pool is manually shutdown.

I realise that there may be cases where the app pool fails catastrophically and doesnt log.

Thanks

Upvotes: 2

Views: 799

Answers (1)

adt
adt

Reputation: 4360

for IIS 7 you can use Microsoft.Web.Administration dll. You can check, create states of pools programaticaly. ApplicationPool.State gives you state of app pool.

Here is an example from iis.net adds a pool.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Administration;
namespace MSWebAdmin_Application
{       
    class Program
    {
        static void Main(string[] args)
        {
            ServerManager serverManager = new ServerManager();
            Site site = serverManager.Sites["Racing Cars Site"];
            site.Name = "Racing Site";
            site.Applications[0].VirtualDirectories[0].PhysicalPath = "d:\\racing";
            serverManager.ApplicationPools.Add("RacingApplicationPool");
            serverManager.Sites["Racing Site"].Applications[0].ApplicationPoolName = "RacingApplicationPool";
            ApplicationPool apppool = serverManager.ApplicationPools["RacingApplicationPool"];
            apppool.ManagedPipelineMode = ManagedPipelineMode.ISAPI;
            serverManager.CommitChanges();
    apppool.Recycle();
        }
    }
} 

http://www.iis.net/learn/manage/scripting/how-to-use-microsoftwebadministration

For IIS 6 Check the status of an application pool (IIS 6) with C#

Upvotes: 1

Related Questions