Tuesday, May 4, 2010

The Power of the App_Offline.htm File in Deployments

There's a little known feature in ASP.NET that I thought was a better known feature until I brought it up at work one day and found out that a lot of people didn't know what I was talking about. For all of you out there who are curious about the in's and out's of the Software Development subculture, yes it is true, we DO sit around and talk about programming all day, often times with great enthusiasm and emotion. There are times I find myself deep in these discussions and think, "wow I am such a geek." Sometimes this is a point of great pride, and other times it is a point of great shame - I guess it depends on the who it is that's listening to said geeky conversation.

Anyhow, let me paint a common scenario - you want to deploy your ASP.NET application out to the World Wide Webs, but you don't want the site to be completely available until some very clever launch date. Let's say your site is called CincoDeMayo.Com*. It certainly would not make sense to launch it on Cuatro de Mayo, now would it?? You do, however, want to let people know that the url is taken and that the site is under construction, or that it's Coming Soon, or something else very exciting. How do I do this with minimal effort? Do I really want to change the default page settings in IIS once launch date comes, or do I want to, God-forbid, hard code some sort of awful redirect on all of my pages until the Launch Date comes to being?? Okay, this is probably not a very common scenario. Let me paint another common scenario that is more likely...

Imagine that you have a site that is already public, but you need the site to come down for maintenance. Maybe you're installing Windows updates on the server, or you need to change a few dll's in the background that have been modified. There is a solution to BOTH of these situations.

In comes the app_offline.htm file!!

This is such a simple thing to do, but quite handy to know. If you include a file called app_offline.htm on any solution folder in IIS, it will automatically lock every other page down on the site, and redirect you to the app_offline.htm. This is a quick and easy way to display some sort of "Maintenance notification" or "Coming Soon Page". When you're ready for the app to be back up, all you have to do is remove or rename this app_offline.htm file and "Voila!", site is back up, live, and kicking.

I actually discovered this by using the "Publish application" feature in Visual Studio. By default, Visual Studio 2005 and above will slip a generic app_offline.htm page onto the destination folder of your deployment while files are being uploaded, and will then remove it once deployment is complete. Again, quite handy, simple, and a good little tidbit of knowledge to know.

*Oh and also, being that today is indeed Cuatro de Mayo, happy Cinco de Mayo everyone!!

No comments:

Post a Comment