OK, the "best way" can be arguable, but this sure is a clean, fast, and stand-alone solution.
In a perfect world, we would never ever need to put our site offline... never!... but we're all grown up now and there's no such thing as a perfect world, and we need to put our sites into a comma stage so we can begin surgery without thinking about outside factors.
The trick: app_offline.htm
There are many ways of putting your ASP.NET website offline but the fastest way is to just drop a file named app_offline.htm on the site's root. Tcharan! That's it folks, good night!
OK, not so fast, I have one more trick up my sleeve.
As you can imagine, this app_offline.htm file can contain HTML markup which will be returned to the user. So you can build your offline page all in there in plain HTML for your users to see. As long as you have this file on the website root, all requests to anything on that website will be redirected to this offline page... an this leads us to a problem...
Showing images on app_offline.htm
This is nice till the point you try to show an image on that page. Like I said above, all requests to anything on this website will be redirected to the app_offline.htm file, and that includes any image file you might want to show on your cute offline page.
To overcome this, you have two options:
- Reference an external image file with a URL that points to another site
- Embed the image file right on the markup
Embedding images inside the app_offline.htm
<img> tags have the ability to consume more than direct pointers to image files, they can read Base64. So the idea is to convert our images into Base64 and inject that code on our page:
<img class="undermaintenanceimage" src="data:image/png;base64,[BASE64 DATA]" />
Just replace [BASE64 DATA] with your image in Base64 format.
If you don't know how to convert an image into its Base64 representation, you may use one of the services online that does that for you; try this one for example.
This way you can create a simple and stand-alone offline file without having to worry about external references or much harder to maintain techniques.