Menu Menu
Offline / maintenance mode in IIS

Offline / maintenance mode in IIS

Before deploying any changes to a live website, we would prefer if there would be a way to put the website in a stable offline/maintenance state, where our website visitors would, for any request, get a nice web page, basically saying the web server is not available, because we are currently busy working on it. This makes our visitors less stressed, comparing to the situation when they would get generic 404/500 error pages, if we just turned off our website or web server completely. It is also worth mentioning that some search engines would most likely penalize our SEO ranking score if our website was frequently unreachable.

In IIS (Internet Information Services), there are several options to put the website in the offline/maintenance mode. One of those options is to make use of the "app_offline.htm" file. Basically, we put a file named "app_offline.htm" in our website's root folder and our visitors will be served with the content of that file for every request they make. This usually means that all the css/js/font/image resources we might be using have to be embedded in that html file, because the web server will always serve "app_offline.htm" for any request. And that's not the only inconvenience when it comes to this approach. There are cases where the web server can lock some files/folders up, making it difficult for us to update those, unless we stop/restart the web application or the entire web server, which we would normally like to avoid, especially on the production web servers.

The more convenient approach could be a creation of a separate IIS website, whose only purpose is to serve the content when our web application is in the offline/maintenance mode. If we setup a new (stopped) website in IIS, with the same bindings as our live website, we could organize all the static html content conveniently, in separate files and folders, without the need for embedding everything into the html file.

Example of offline/maintenance mode website in IIS

Also, the file/folder locking issues will be avoided simply because of the fact that the offline-mode IIS website is hosting its files from a completely separate folder compared to the live website, using different application pool, as well. In our case, we created a single index.html file for the offline mode with some css/js/images around it and even configured our application pool to be in "No Managed Code" mode, since we are only serving static files, anyway.

Example of a non-managed app pool in IIS

When we get to the point where we need to put the live website to offline/maintenance mode, we would just stop the live website and start the offline-mode website in IIS, with a couple of clicks of our mouse.

Example of stopping a website in IIS

Example of starting a website in IIS

We also have to redirect all the requests to the non-existent pages (404) to that single index.html file, in order to display one page for any page that visitors might have bookmarked. Since the offline-mode website only has one single valid page/url, all the other requests will produce a 404 response, which we will handle by redirecting visitors to that single html page we can serve, while the website is in offline mode. This is easily accomplished with the following web.config:

<?xml version="1.0" encoding="UTF-8"?>
		<httpErrors errorMode="Custom" defaultResponseMode="Redirect">
			<clear />
			<error statusCode="404" path="/" responseMode="Redirect" />

There are, of course, other ways to accomplish the offline/maintenance mode in IIS, but we chose this one to avoid being restricted to the big fat app_offline.htm file with all the resources embedded inside it and to avoid file/folder locking issues. Accomplishing a sensitive task like putting our website to the offline state, in a stable way, with just a couple of mouse clicks, made it a bit more appealing.

Latest blog posts
How to Display Jenkins Build Status Badge on GitHub
What It Looks Like to Work with Our CEO
Boban Miksin, CTO at Vega IT Coding Month at Vega IT: Coding Dojo
What Is Salesforce And How Can Your Company Benefit From It?
We Are the IT City: How We Have Organised an Online Conference