Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Best Way to Put Your ASP.NET Site Offline

0.00/5 (No votes)
20 Jul 2011 1  
A clean, fast and stand-alone solution

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... and 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:

  1. Reference an external image file with a URL that points to another site
  2. 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:

HTML
<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.

Conclusion

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here