2

I'm using ServerManager to manage app sites and app pools remotely. However there are no methods to control or query the status of an actual application.

IIS Manager Context Menu

I have code for app pool

public string StopAppPool(string poolName)
{
        using (var iis = ServerManager.OpenRemote(this._server))
        {
            return iis.ApplicationPools.First(ap => ap.Name == poolName).Stop().ToString();
        }
}

and for site

public string StartSite(string site)
{
        using(var iis = ServerManager.OpenRemote(this._server))
        {
            return iis.Sites.First(s => s.Name == site).Start().ToString();
        }
}

but the Application level doesn't have those methods at all.

public string StartApp(string site,string path)
{
        using (var iis = ServerManager.OpenRemote(this._server))
        {
            iis.Sites[0].Applications[0]. // not here =(
        }
}
Maslow
  • 18,464
  • 20
  • 106
  • 193
  • 1
    Possible duplicate of http://stackoverflow.com/questions/1148511/is-it-possible-to-start-stop-an-application-pool-or-website-in-iis-programatic?rq=1 – Rui Jarimba Dec 27 '12 at 16:04
  • @RuiJarimba: Not a dupe of that. This is app specific. – NotMe Dec 27 '12 at 16:34

1 Answers1

0

You might want to read the following: http://www.iis.net/configreference/system.applicationhost/applicationpools

An "application" only runs for as long as the request is active due to how the web works. So, unless there is a long running thread, it is only active as it is currently processing a request. If you need to check on this you can use some of the WMI features to get the number of active requests. However, just because a particular application isn't currently processing requests doesn't mean it's not available to do so.

Essentially, a request comes in and starts off within IIS itself. IIS then looks up the handler for the request and passes it to the correct site / app pool. There are subtle differences depending on if you are using Integrated or Classic mode but for your question these don't matter.

A site may be inactive if it is turned off, or if it's application pool is turned off. That level of granularity is provided so that you can share app pools among multiple sites and allow some sites to be on while others are off or to turn off all the sites within an app pool at once.

Within a given site, the application itself is always enabled provided the site is enabled so there is no way to control whether that particular application is on or off outside the context of the entire site being on or off.

If you need to shut down particular applications, then you should split them into different sites and control them at that level.

NotMe
  • 87,343
  • 27
  • 171
  • 245
  • According to IIS Manager in the screenshot provided, you can Start/Stop an application within a site. – Maslow Dec 27 '12 at 20:20
  • @maslow: In the screen shot they are mixing the terms "site" and "application" for easier readability. Most people don't think of a "wcf site" they think of a "wcf application" or "wcf service". From the perspective of IIS however, the "WCF Application" is just another site. – NotMe Dec 27 '12 at 21:14
  • ok, but you can stop the application, while the rest of the 'site' continues to function. So whatever the terms are, I'd still like to be able to start/stop at this level of granularity. – Maslow Dec 28 '12 at 15:07