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

Registry manipulation from SQL

Registry Manupulation from SQL Server is pretty easy. There are 4 extended stored procedure in SQL Server 2000 for the purpose of manupulating the server registry. They are: 1) xp_regwrite 2) xp_regread 3) xp_regdeletekey 4) xp_regdeletevalue Let us see each one of them in detail! About xp_regwrite This extended stored procedure helps us to create data item in the (server’s) registry and we could also create a new key. Usage: We must specify the root key with the @rootkey parameter and an individual key with the @key parameter. Please note that if the key doesn’t exist (without any warnnig) it would be created in the registry. The @value_name parameter designates the data item and the @type the type of the data item. Valid data item types include REG_SZ and REG_DWORD . The last parameter is the @value parameter, which assigns a value to the data item. Let us now see an example which would add a new key called " TestKey ", and a new data item under it called TestKeyValue :

Screen scraping using XmlHttp and Vbscript ...

I wrote a small program for screen scraping any sites using XmlHttp object and VBScript. I know I haven't done any rocket science :) still I thought of sharing the code with you all. XmlHttp -- E x tensible M arkup L anguage H ypertext T ransfer P rotocol An advantage is that - the XmlHttp object queries the server and retrieve the latest information without reloading the page. Source code: < html > < head > < script language ="vbscript"> Dim objXmlHttp Set objXmlHttp = CreateObject("Msxml2.XMLHttp") Function ScreenScrapping() URL == "UR site URL comes here" objXmlHttp.Open "POST", url, False objXmlHttp.onreadystatechange = getref("HandleStateChange") objXmlHttp.Send End Function Function HandleStateChange() If (ObjXmlHttp.readyState = 4) Then msgbox "Screenscrapping completed .." divShowContent.innerHtml = objXmlHttp.responseText End If End Function </ script > < head > < body > &l

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