Skip to main content

App_offline.htm – ASP.NET 2.0 new feature

It’s an interesting find. I got few mails asking me suggestions on the way to handle situations where “the application needs to be updated with the latest code base”. I was preparing a blog post something like this:

1. Normally sites are deployed in Web farm scenarios. If your app is also deployed in a web farm then it’s better to bring one server down update the code base there while all the user request would be served by the other servers in the farm. This way the downtime of the application would be almost zero.

2. If at all your application is deployed on a single server then either you need to face the downtime :) or temporarily create another virtual directory with the old code base. This Virtual directory would be functional till the time you update the actual directory with your latest code base. There would be some negligible amount of downtime here.

3. If you can’t create a new virtual directory for some reason! Then create a static page (“SiteDownForMaintanance.htm”) and based on a flag in your “web.config” redirect all request to this static page. Once the code base has been updated, change the Boolean flag in your “web.config” to false.

I am sure there might be other options to resolve this too. So I started (re)searching through the web to read how experts have handled similar situations in their projects. During one such (re)search I found about “App_offline.htm” concept in ASP.NET 2.0.

The concept seems to be really simple / cool. Let me explain it for those who haven’t heard about it.

1. We need to create an html page with name “App_offline.htm”. Put whatever junk content you want to display to your user during the application maintenance!

2. Now run any page in your application to see the content of “App_offline.htm” to be displayed.

3. Once you have done with your updates or maintenance remove this file from your project. That’s all.

Though I have read that “Excluding this file from project” is also enough it didn’t work for me. It worked only when I removed it from the project or renamed it to something else.

From ScottGu’s blog i came to know that
“The way app_offline.htm works is that you place this file in the root of the application. When ASP.NET sees it, it will shut-down the app-domain for the application (and not restart it for requests) and instead send back the contents of the App_offline.htm file in response to all new dynamic requests for the application. When you are done updating the site, just delete the file and it will come back online.”

Interesting isn’t it?

There is another point which I would like to bring to your notice. From ScottGu’s blog I came to know about this as well
“One thing I pointed out in the talk that you want to keep an eye on is a feature of IE6 called "Show Friendly Http Errors". This can be configured in the Tools->Internet Options->Advanced tab within IE, and is on by default with IE6. When this is on, and a server returns a non HTTP-200 status code with less than 512 bytes of content, IE will not show the returned HTML and instead substitutes its own generic status code message”

I am not sure whether he is wrong or in IE 6.0 SP2 they have changed it! because I created an “empty App_offline.htm” page and it worked. The Browser Version in my system is IE 6.0 SP2 and “Show Friendly Http Error Messages” is by default checked in it.

Technorati tags: ,

Comments

I think this is interesting, since, when I publish my app to its local directory, using Visual Studio, I find that app_offline.htm coming up, and I want to customize it.

From what I've been reading, it seems pretty general that you can either put it in manually to take things down for a bit, or you can allow Visual Studio to put its own app_offline.htm when publishing to an existing application folder.

If I can, I'll figure out how to get the default app_offline.htm used by Visual Studio to be a little more explicative in its purpose and what-not, so my testers know the site is down, but it will be back as soon as it's re-published.

Thanks for your article though, I really enjoyed it.

Popular posts from this blog

Script table as - ALTER TO is greyed out - SQL SERVER

One of my office colleague recently asked me why we are not able to generate ALTER Table script from SSMS. If we right click on the table and choose "Script Table As"  ALTER To option would be disabled or Greyed out. Is it a bug? No it isn't a bug. ALTER To is there to be used for generating modified script of Stored Procedure, Functions, Views, Triggers etc., and NOT for Tables. For generating ALTER Table script there is an work around. Right click on the table, choose "Modify" and enter into the design mode. Make what ever changes you want to make and WITHOUT saving it right click anywhere on the top half of the window (above Column properties) and choose "Generate Change Script". Please be advised that SQL Server would drop actually create a new table with modifications, move the data from the old table into it and then drop the old table. Sounds simple but assume you have a very large table for which you want to do this! Then it woul

AWS fatal error: An error occurred (400) when calling the HeadObject operation: Bad Request

While using AWS and trying to copy a file from a S3 bucket to my EC2 instance ended up with this error message. Command Used: aws s3 cp s3://mybucketname/myfilename.html /var/www/html/ Error: fatal error: An error occurred (400) when calling the HeadObject operation: Bad Request The error goes off if we add the region information to the command statement. I am using Asia Pacific (Mumbai) so used ap-south-1 as the region name. Modified Command: aws s3 cp s3://mybucketname/myfilename.html /var/www/html/ --region ap-south-1

[Non Tech] Want to know the recipe for Omelette :)

Fed up with Bread - Jam and Curd Rice, today i wanted to eat Omelette. Interesting part is I wanted to cook it myself :) So in the first picture you see all the items which are needed for preparing an Omelette. When I had a closer look at the eggs I see that almost all the eggs are broken. But believe me when I bought it couple of days back it was in perfect condition! I was wondering whether the eggs have become rotten or pretty old to consume! I tried taking an egg and break it but couldn't break it at all :) Since I have kept in the freezer all the eggs have frozen and looked like a iron ball :) After trying for few minutes of trying i removed the shell of the egg and then kept that iron ball :) into a bowl and placed it within Oven. I heated it for 1 minute and checked. It melted only to a limit. So i just set it for another 2 minutes and checked it later. It has melted but the part of the egg white has become a Omelette :( I didn't leave it there. I took the bowl out of