Reputation: 880
I have a ASP.NET web application running under IIS 6, and another process that is responsible to monitor and report status.
I'd like to sample the web application by the monitoring process in order to check its status by accessing a dedicated handler on the web application, BUT i don't want to "wake up" the web application in case it is not running.
Is there an option to determine whether a specific web application is currently running? if there is such an option, i would be able to first check if the application is running, and only then to access the handler to check its status.
Thanks.
Upvotes: 7
Views: 6824
Reputation: 16567
We used to use Nagios to monitor our site and it would target the favicon of our website. If it could pull back the icon, we knew the site was up.
Upvotes: 0
Reputation: 18804
I had to do something similar earlier this year for IIS7, not sure if this would work for IIS6 but here's what I did.
var iis = new DirectoryEntry("IIS://" + Environment.MachineName + "/w3svc");
foreach (DirectoryEntry site in iis.Children)
{
if (site.SchemaClassName.ToLower() == "iiswebserver")
{
Console.WriteLine("Name: " + site.Name);
Console.WriteLine("State: " + site.Properties["ServerState"].Value);
}
}
ServerState returns 2 for started and 4 for stopped.
Upvotes: 2
Reputation: 1621
You can use the HTTP HEAD request to check if the site is up or not. Here is an example to do the same.
Upvotes: 1
Reputation: 43531
This is my solution:
try
{
WebRequest request = WebRequest.Create("http://localhost/");
WebResponse response = request.GetResponse();
}
catch (WebException ex)
{
// ex.Status will be WebExceptionStatus.ConnectFailure
// if the site is not currently running
}
Upvotes: 0
Reputation: 52538
You could analyse the IIS log file, to see if there are recent entries.
If your application is not used much, it is possible the latest "entry" still needs to be flushed.
Or you could update a file/database to indicate "still active".
If you really do not want a delay, in the Application_Start and Application_End, create and destroy a system mutex.
Upvotes: 0
Reputation: 9519
I would include in the ASP.NET website an asmx file, a web service with a simple Ping function, but it will still wake up the application pool of the website.
Upvotes: 0