asp.netapp-offline.htm

What are suggested alternatives to the often broken app_offline.htm hack?


In quite some scenario's, placing app_offline.htm in the root is just right: you do some updates, the message appears while updating, and that's that. The idea is, as Microsoft puts it, that before anything is called, IIS first checks if app_offline.htm is there and if so, it cancels everything and displays it.

So for so good, but in many situations it doesn't work:

Possibly more scenario's exist that fail. My point is: for any serious updating work, app_offline.htm is not suitable. I sometimes create a redirect in IIS, to another site, but another site may not always be available and it can confuse users.

Ideally, I'd want to keep the current location in the url location bar of the end-user, show the message, and have the page auto-refresh each minute to see whether the site is back, so that the user continues where he left of when the site comes back. While technically easy enough with a static page, it will fail for the above mentioned reasons the minute an error is thrown.


Solution

  • No one else mentioned web.config and recompilation, so here it is. I've encountered this issue. I disagree with the person who said it's "not intended for prod use": VS 2010 uses app_offline when deploying so it's baked into the code.

    The workaround (credit goes to Kurt Schindler, blog post here).

    1. copy up app_offline.htm to your site
    2. make a web.config that looks like this (see below numbered block)
    3. copy that web.config up to your remote directory
    4. copy all of the site files except your true web.config up to the remote dir
    5. copy the real web.config up to the remote dir (which should kick off a recompile)

    web.config:

    <?xml version="1.0" encoding="utf-8" ?> 
    <configuration>
      <system.web>
        <httpRuntime waitChangeNotification="300"
           maxWaitChangeNotification="300"/>
      </system.web>
      <system.webServer>
         <modules runAllManagedModulesForAllRequests="true"  />
      </system.webServer> 
    </configuration>
    

    The consequence of this is that you can't use the VS 2010 app deployment directly if you care about end users not seeing YSOD during a deploy. So you'll need to use Nant or some other deploy tool to do this.