Lee Kelleher

Putting your ASP.NET Web Application in Maintenance Mode (using ISAPI_Rewrite)

Prompted by @slace’s tweet:

I replied with a suggestion that we’ve used in the past. Aaron said I should blog about it… so here I am (again)!

A while ago we needed to do an Umbraco upgrade (from v3 to v4) on a production server – in my opinion it was a pretty major upgrade on a live site, we had done a couple of test upgrades on dev and staging, all was successful.  But since there was various parts of the site that we need to regression test, I felt it best to take the entire site offline whilst we upgraded.

Usually creating an “App_Offline.htm” page in the root of your web app is enough to take it offline.  However that was no good for testing… so what to do?

This is where ISAPI_Rewrite is your best friend, (or .htaccess to be precise).  We needed to configure the site to allow access for us and redirect everyone else to a “Site under maintenance” page.  I found a few examples across the web, but to save you all that hassle, here are the .htaccess rules that we use:

# BEGIN Maintanence Mode
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/offline.html$
RewriteCond %{REMOTE_ADDR} !^82.13.23.230$
RewriteRule ^(.*)$ /offline.html [R=302,L]
</IfModule>
# END Maintanence Mode

What does it do? The first “RewriteCond” rule checks that you are not requesting the “offline.html” page (otherwise you would end up in a constant loop!) The second “RewriteCond” checks the IP address of the visitor – in my case it was “82.13.23.230″ (remember to escape the dots). If those two rules aren’t satisfied, then the “RewriteRule” is used, redirecting the visitor to the “offline.html” page.

As always, I am open to any suggestions or improvements!


  • http://www.netaddicts.be Dirk De Grave

    Great tip Lee and thanks for sharing

  • http://thereturnvalue.com eran

    nice tip thanks!
    i think it will be great to see an umbraco package that can take care of it and enable the user to turn the site offline with a single checkbox, except specific ip. maybe i can help to develop it, with some guidelines from you.

  • http://leekelleher.com/ Lee Kelleher

    Hi Eran, while it is possible to control a website’s maintenance mode from the Umbraco back-office – its not suitable for upgrading Umbraco itself.

    Basically you want to be ‘outside of ASP.NET’ when doing an upgrade, which is why I used ISAPI_Rewrite, but you could easily do this in IIS7 too!

    If you are thinking of a more generic ‘maintenance mode’ package for Umbraco – say if you wanted to take your website offline quickly, then – sure it’s achievable!

    Drop me an email next week (I’m on holiday this week)
    http://leekelleher.com/contact/

    Cheers, Lee.

  • http://thereturnvalue.com eran

    HI lee, accidentally just now saw you replay..
    any way, the umbraco package idea is not so good – if the umbraco instance is down for major maintenance, maybe the whole asp.net is not available. if i’m wrong please correct me.
    anyway i will stay with the app_offline.htm for now. one thing to keep in mind with this file however, make sure it is larger than 512 bytes or IE will consider it a 404 and will display the 404 instead of the contents of your app_offline.htm file. (or map the 404. 403.1 errors to app_offline.htm)