(Microsoft .NET,Microsoft IIS,Microsoft ASP.NET)
by Jason Skowronek
on 10/27/2009
Updated December 14, 2011
App_Offline.htm Static Override Page (preferred)
Adding a file in the application root named App_Offline.htm automatically causes the AppDomain to recycle and modifies its behavior such that any request for an ASP.NET resource returns the contents of the App_Offline.htm file instead (along with an HTTP 404 status). Deleting App_Offline.htm automatically recycles the AppDomain again and the web application is back to serving its usual content.*
- Create a static HTML page called App_Offline.htm
- Filesize must be at LEAST 512MB and cannot exceed 1MB in order to work properly as an offline mode trigger
A caveat to using the app_offline.htm method is that all local resources such as images and stylesheets are also taken offline and are unavailable. There are various solutions to this problem, the easiest of which is to embed the resources directly into the page as data.
The following loads an image that has been base 64 encoded and embedded on the page:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAAAuCAMAAAD9RhDIAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAGNQTFRFkpSQYbVqsNq0ra+s1+zaiciP+Pj4mZuXyMnH5OTjp6ilu7y61tfV6uvqtLazxOPH8fLx4fHjdb59a7pznNGik8yZ9fr26/bsz9DOzejQoKGe3d3cwsPBf8OGut6+ptar////yEvtTQAAACF0Uk5T//////////////////////////////////////////8An8HQIQAABCVJREFUeNrsmNeCmzAQRWVASKJX01z4/6+MQL2AvUk22QfP0y7C6DBzNQWw+m0E1Ir1fxk4uB5uWOCD9cH6YH2TDR2EMPhxWMFls/pnYkUfrA/WP8PKyYgXEr+LFROC6f358R1RGUzR1bdS06Uyql9jkRQBZvOt8mPhhP4fssXqNgNhRaaRNJdLM+1/9Rdm99Km7Vq+1PaMoqYZCzbsbsis3naOC6Ab9mGlbG1jqMzbARqNV6Y58SqgNoO6x2p40Q1uLnteHOvpzjkytwG5i5WxlYQGObNvp06MDay6NfZoFFdp799SZ0IXC4I1TuxdiIOlUwGPJbGG5ex9P6SiVq6d11uYRQLnm4530ThYHiqUYip6KclCYd05yzPoGrm1TtU+qaaGidO0Q9Q6PpzAuj8ZVdIxyAkij/JGVSH+EuLIjkiJjh+nHYqp+cHDyKox274TMa3ZC0DvSSTqqfzo55bkNaqVqR1peYGvzgZWJ1Y5154MOnOJnoxWLdpYmT9BKaxKo8qV+BSXcldgBm0zpuetYxk033CbFKiNhV9g8RPBRM3SRGremkp1cayHtsj01Lsb79bIEPu9tRxhGVRMh6Ayb62AeIXADhMNlPTR3TiUem4fDrU1xwdYoU7F4hXar5CIyLJnr16HDDKaThQjX/HhZ4t4sVKdis20rArodtsvj34syK9Fnhjyiw8fFhapenGxTCq+P7GxMkF7hsXWHpFhD+lCt1TLLD/jysJSxUi7WNlYRByE11he82Pp1acgHqzkRbdDhOTOsPqvYq0yjkD1LoyAiUlmhAOs+B0seIxVHvVbVaraArRoBAXQi8ABVv5nWP31uDuNx9nX2PAA82pzGsT0nSBGX+/l81RIXyMQJS9WWMSP9dZJ/A0sGstExkw6JtM6l9RfEbD40TdhiQ6h0OPFfTjK/W/2IwsR+jOsyZfl38WKEVevwhL5g4hoJavvN2g9x/I0EF+YE0MHS7Z+VF7AJ65MJpEzLFYc97L8d7DWBYgMUHhqNXPWznqK9XTbCwdrUh1E7mbGwsoFrBZSUS1KZ5aywvUV1uC0iG4v8ZRYFKKyW7rMTlFcXov4QzURYsYkL7FE+TG5pp7NkayXaK8Ki+qCn3k+mG4qMrF4oFBORGrL9kRWYQS003mOxUeMCxShuk7PVgpKjSbDA06i4oQpLhJtrLYSOhEjmSqfKAztYn6OpY2JUM33Aqszx1fXUl+dwWIt9fzCmKqPsbzjq/gyWZtY2Evllr9QyMsd9rF5nI6x9m8ntnWekbsDKzG+dIREO19IP6OzQIhTAyyt1jOsXeitnDgCE6zp1PekUk3X0z5zZbdw2zQsRpkt4hFjbPSh+5VxD1e83MJNiHN4y/TZ5PoIgsAqe/s1PYnWQQ/ZR6NnaX7jupY9bFrYP4b1lwADAHRMJJPCmDsVAAAAAElFTkSuQmCC" />

I used a free base 64 encoded for the example above: Free Base 64 Encoder
Redirect the entire IIS Application (alternative)
- Create an offline or maintenance mode web page (per design specifications or use default version) and save the page to the application root directory
- Open IIS manager on the web server that is hosting the site/application
- Right-click the site/application name | Properties
- Click the "Home Directory" tab (or "Virtual Directory" tab if an application)
- Select "A redirect to a URL"
- Enter the fully qualified URL to the offline page
- Check "The exact URL entered above" checkbox
- Click Apply | OK