How to handle taking application offline

I have a web project with multiple sites and steps that need to be run for a deployment (deploy Website1, deploy website 2, update database, etc)

I want to put the website offline so that no one can access it while I am updating the database/websites.

Does anyone know a nice way (power shell script to take site off line via app_offline file?) to make my site offline until the whole deployment is complete?


Easy way is to slap a app_offline.htm file in the root directory of each site.

The hard part is knowing when all the requests have finished.

Turns out it was pretty easy …



Import-Module WebAdministration
# see

cd IIS:\

if ( (Get-WebAppPoolState -Name $appPoolName).Value -eq “Stopped” )
Write-Host "AppPool already stopped: " + $appPoolName

Write-Host "Shutting down the AppPool: " + $appPoolName
Write-Host (Get-WebAppPoolState $appPoolName).Value

Signal to stop.

Stop-WebAppPool -Name $appPoolName

Write-Host (Get-WebAppPoolState $appPoolName).Value
Start-Sleep -Seconds 1
until ( (Get-WebAppPoolState -Name $appPoolName).Value -eq “Stopped” )

In case the next person who wants to do this searches first on tack overflow …