Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Best way to put your ASP.NET site offline

, 20 Jul 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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! Smile | :)

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:

  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:

<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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

AlexCode
Architect
Switzerland Switzerland
Senior IT Consultant working in Switzerland as Senior Software Engineer.
 
Find more at on my blog.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 20 Jul 2011
Article Copyright 2011 by AlexCode
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid