App_Offline.htm

Update: A newer post about this can be found here.

 

I was planning to break the news about the little-heard-of app_offline.htm feature in ASP.NET 2.0, but Erik beat me to it. J

 

Basically, if you place a file with this name in the root of a web application directory, ASP.NET 2.0 will shut-down the application, unload the application domain from the server, and stop processing any new incoming requests for that application.  ASP.NET will also then respond to all requests for dynamic pages in the application by sending back the content of the app_offline.htm file (for example: you might want to have a “site under construction” or “down for maintenance” message).

 

This provides a convenient way to take down your application while you are making big changes or copying in lots of new page functionality (and you want to avoid the annoying problem of people hitting and activating your site in the middle of a content update).  It can also be a useful way to immediately unlock and unload a SQL Express or Access database whose .mdf or .mdb data files are residing in the /app_data directory.

 

Once you remove the app_offline.htm file, the next request into the application will cause ASP.NET to load the application and app-domain again, and life will continue along as normal.

 

Hope this helps,

 

Scott

Published Thursday, October 06, 2005 7:24 AM by ScottGu

Comments

# re: App_Offline.htm

Thursday, October 06, 2005 10:31 AM by M. Keith Warren
Can we override the file name via web or machine .config ? Just curious.

# re: App_Offline.htm

Thursday, October 06, 2005 10:33 AM by Travis
Cool news...

# re: App_Offline.htm

Thursday, October 06, 2005 10:36 AM by scottgu
Hi Keith,

Unfortunately you can't override the name. One reason is that we need to implement this logic very early in the request cycle -- before your application is even loaded (and so any config-related information specific to the application doesn't exist yet).

We used the name app_offline.htm because we thought it would be pretty unique and would avoid conflicts with any app already out there.

Hope this helps,

Scott

# re: App_Offline.htm

Thursday, October 06, 2005 10:45 AM by Simon Armstrong
Scott,

Sounds quite useful, but is this for all incoming requests, or does it only cover requests from new users (those that would result in a new "session")?

For example, I visit the site and start reading some content, or filling in a form, etc. While I'm doing that, you copy the file up to the server. I then click on a link to go to another page, or submit a form ... what would happen?

Actually, maybe you could answer a question from a colleague of mine about if you can stop accepting sessions in ASP.Net and monitor when all existing activity has terminated.

thanks
Simon

# re: App_Offline.htm

Thursday, October 06, 2005 11:06 AM by Todd Gray
Can you achieve the same results by renaming a file to App_Offline.htm (e.g. toggling between App_Offline.htm and App_Offline.xxx), or is the trigger when the file is created in the directory?

# re: App_Offline.htm

Thursday, October 06, 2005 11:23 AM by scottgu
Hi Todd,

Yep -- any file-change to app_offline.htm will trigger it. So renames will cause it as well if you want to use a toggle file.

Thanks,

Scott

# re: App_Offline.htm

Thursday, October 06, 2005 12:15 PM by laurence timms
Excellent. That's exactly the kind of useful, practical feature that we need. Cheers! :)

# re: App_Offline.htm

Thursday, October 06, 2005 12:21 PM by Edwin
This is cool news. Thanks Scott

# re: App_Offline.htm

Thursday, October 06, 2005 12:32 PM by Keyvan Nayyeri
That's helpful ;)
Trackback:
http://nayyeri.net/archive/2005/10/06/204.aspx
Thank you.

# re: App_Offline.htm

Thursday, October 06, 2005 3:06 PM by Milan Negovan
Hi Scott,

That's a very helpful feature, imho! One thing that bothers me about "magic file names" in general is that they exist covertly. For example, I can't tell you how many page hits I got over this post on "get_aspx_ver.aspx": http://www.aspnetresources.com/blog/WhatIsGetAspxVer.aspx

Can you, guys, publish a list of these "magic pages" so we know of them, know how they are treated, etc? Otherwise we'll dig 'em out anyway :), but it's better to have them documented.

# re: App_Offline.htm

Thursday, October 06, 2005 3:50 PM by Gregor Suttie
Sounds very cool - seems a little easy to bring down a website though - need to make sure its an admin function perhaps otherwise someone can bring your site down rather easily.

# re: App_Offline.htm

Thursday, October 06, 2005 4:09 PM by Erik Porter
Oops, sorry, Scott. Didn't mean to steal your thunder. Your explanation is better than mine anyway. ;)

# re: App_Offline.htm

Thursday, October 06, 2005 6:32 PM by timh
this only works with IIS or does cassini support that as well?

# re: App_Offline.htm

Thursday, October 06, 2005 10:16 PM by Sonu Kapoor
Cool feature..

# re: App_Offline.htm

Thursday, October 06, 2005 10:25 PM by Steve Bargelt
Awesome. This feature rocks.
Trackback: <a href="http://www.geekswithblogs.com/sbargelt/archive/2005/10/06/56276.aspx">http://www.geekswithblogs.com/sbargelt/archive/2005/10/06/56276.aspx</a>

# re: App_Offline.htm

Friday, October 07, 2005 1:48 AM by Sunny NAGI
This is pretty cool...

I like it...specially this will take care of search engines trying to sniff through your server.

# re: App_Offline.htm

Friday, October 07, 2005 2:17 AM by Mital Kakaiya [MCSD.NET]
Really nice feature.

Does it allow any IP range filter eg: do not display "Under Construction" webpage for internal developers? Generally, developers need to verify major upgrade, before it goes to live world.

# re: App_Offline.htm

Friday, October 07, 2005 3:28 AM by Jelle Druyts
Pfeh, I beat you both to it 5 months ago: http://jelle.druyts.net/2005/05/23/WhenASPNET20Throws404sAtYou.aspx :-p

I'm wondering though if it's a good idea to let the mere presence of such a simple file bring down your entire app. If a hacker gets to place the file on your web root somehow you'll be wondering what happened for quite a while... Admittedly, if he gets that far, he can likely do a lot worse; but still, it feels fragile.

# re: App_Offline.htm

Friday, October 07, 2005 4:08 AM by GS
another great feature for 2.0. cant wait, scott you and your team are doing a fantastic job. roll on the release day.

# re: App_Offline.htm

Friday, October 07, 2005 5:28 AM by Prakash Sachania
This is a good feature to have. However, it seems static. Why not have an object or something registered to IIS that will return true or false.
For example, application might be ready to become offline after serving existing sessions. And would not be willing to take new sessions. I do not see why an e-commerce application in the middle of its operation would want to go offline, affecting their business. Approach would have to be so that new sessions are not created.

But it is a first step. And seeing that web server is taking take care of it, is relieving. One less programming headache.

-Prakash

# re: App_Offline.htm

Friday, October 07, 2005 5:34 AM by Ruud Luttmer
What if (I think) visual studio is creating the by it self. I have done some testing with the preview release of july and wefly247, and everytime I started the studio, the App_Offline.htm was created. Haven't seen it in the RC so maybe it was a bug in de preview release.

# re: App_Offline.htm

Friday, October 07, 2005 7:35 AM by David
This is one of those really cool simple things that are extremly useful. But they often fall in the shadow of all the new major features that steal the spotlight, and therefore don't get as much documentation. So you just fell happy when you by accident stumble onto one.
But your team have probably implemented plenty more like this one, so will there be a white-paper of all the other ones? I want to know about every little change and new feature. :)

# re: App_Offline.htm

Friday, October 07, 2005 8:16 AM by David Taylor
Hey Scott - Welcome back from you holiday. I truly hope you could forget about ASP.NET and IIS for at least a few days while away ;-)

# re: App_Offline.htm

Friday, October 07, 2005 8:32 AM by Paritosh Mhaisekar
Thats a really nifty and useful feature..
cheers

# re: App_Offline.htm

Friday, October 07, 2005 10:07 AM by Ranjit
My friend says, "The only thing that would make it better is if we could rig it so we could still go into the system while everyone else can not. For example, if it allowed only the current box/hosting server to be able to use the system by typing in http://localhost/..."

Will this be possible?

Ranji

# re: App_Offline.htm

Friday, October 07, 2005 10:12 AM by Edgardo Rossetto
wow

COOL

# re: App_Offline.htm

Friday, October 07, 2005 10:24 AM by scottgu
Hi Ruud,

Yep -- in the Betas there was a bug that caused the file to occasionally get generated and not cleaned up when new databases are provisioned. Hopefully it no longer exists (I haven't run into it for a few months)!

Thanks,

Scott

# re: App_Offline.htm

Friday, October 07, 2005 10:27 AM by scottgu
Hi Mital,

It doesn't allow IP range filtering. One challange with IP range filtering is that it is easy to defeat and bypass. Anyone can send a packet saying it is from another IP address -- the response from the web-server wouldn't reach them (if the IP address wasn't real), but it would still activate the app and cause things to run.

Hope this helps,

Scott

# re: App_Offline.htm

Friday, October 07, 2005 10:31 AM by scottgu
Hi Simon,

We actually have perf counters that track session creation and the number of active sessions. So if you wanted to count these you can using this infrastructure. The app_offline.htm trick is designed to provide a pretty easy and bare-bones way to take down your site and app-domain for upgrading bits. If you wanted to provide a more graceful approach, you could ceretainly implement one by rejecting sessions and slowly weaning people off the server before you then dropped a app_offline.htm file to finally shut it down.

Hope this helps,

Scott

# re: App_Offline.htm

Friday, October 07, 2005 10:34 AM by scottgu
Hi Tim,

App_Offline.htm will also take down apps with Cassini, although honestly it probably doesn't make sense using it there. It is easier to just right click and stop Cassini vs. adding the file.

Hope this helps,

Scott

# re: App_Offline.htm

Friday, October 07, 2005 12:37 PM by Mike Ober
Great - one of the problems I have with classic ASP is that I would actually have to toggle the IIS service to unlock files before I could do a site upgrade.

Mike.

# re: App_Offline.htm

Friday, October 07, 2005 5:11 PM by Mwahaha
As a prank for your fellow developers, create the file but don't put any text in it. This causes a 'resource not found' error! - but doesn't mention anything about the app_offline.htm file! You can sit back and laugh while your peers struggle for hours trying to figure out why the site doesn't work anymore!

# Soci blog &raquo; Blog Archive &raquo; Kev??ss?? ismert ASP.NET 2.0 tr??kk

PingBack from http://soci.hu/blog/index.php/2006/05/22/kevesse-ismert-aspnet-20-trukk/

# Keyvan Nayyeri : App_Offline.htm file in ASP.NET 2.0

Saturday, July 15, 2006 1:56 AM by Keyvan Nayyeri : App_Offline.htm file in ASP.NET 2.0

PingBack from http://nayyeri.net/archive/2005/10/06/204.aspx

# App_Offline.htm file in ASP.NET 2.0

Sunday, July 16, 2006 4:16 AM by Keyvan Nayyeri

Scott Guthrie has written about App_Offline.htm file in ASP.NET 2.0. You can place it in root of your

# Upgraded to Community Server 2.1 beta 1

Saturday, July 22, 2006 12:00 AM by Thomas Freudenberg's Blog

Finally I managed to update my site. I already missed the last major step from 1.1 to 2.1. However, during

# App_Offline.htm "IE Friendly Errors"

Thursday, September 07, 2006 3:39 AM by Fouz Blog

Jos&eacute; M. Alarc&oacute;n ya escribi&oacute; en un post sobre App_Offline.htm , cit&aacute;ndole

# Links of the Week

Thursday, September 14, 2006 3:00 AM by Rick.Stavanja.com

As usual, I&#39;ve been too busy to blog lately, but I thought I&#39;d try something new; I&#39;ll try

# re: App_Offline.htm

Tuesday, September 19, 2006 4:28 AM by Scanner
Scott, How come every time I install any security updates and reboot the server the App_Offline.htm appears so my site never comes back online automatically. If it is a feature that is built in can i disable the option for it to automatically be created after every security update and reboot

# re: App_Offline.htm

Wednesday, September 20, 2006 12:02 AM by ScottGu

Hi Scanner,

The app_offline.htm file is only ever generated by VS (ASP.NET and Windows never generate it).  It shouldn't be happening when installing security updates.  Can you provide more details on when/how this is occuring?

thanks,

Scott

# re: App_Offline.htm

Friday, September 22, 2006 5:12 PM by Rich
Is there a way to get around this file permanantly? I'm testing an app that is using MS Access 2003 as a back-end and this app_offline.htm file suddenly shows up because the .ldb file on the Access database didn't close because I made an error in my code while saving data and the connection stayed open. I had never seen this file before and when I looked for it, it was not in the root directory as Firefox and IE said it was. Any idea as to how I can get around this file so I can test. I'm using VS 2005, ASP.Net 2.0 on a W2003 Enterprise server coding in VB.Net. I'm also connecting to PayPal since this is a fund raising site. Many thanks, Rich

# re: App_Offline.htm

Sunday, September 24, 2006 12:02 PM by ScottGu

Hi Rich,

From your message above, it doesn't sound like you are seeing the app_offline.htm file.  Rather, it sounds like you are having runtime errors within your application - which is triggering the default ASP.NET error message to display.  

These pages provide more details on how to handle custom errors within ASP.NET:

http://www.aspnetresources.com/articles/CustomErrorPages.aspx

http://www.c-sharpcorner.com/vbnet/vbarticles/VBASPExHSSK.asp

http://www.aspnetpro.com/NewsletterArticle/2003/07/asp200307mb_l/asp200307mb_l.asp

Hope this helps,

Scott

# re: App_Offline.htm

Monday, September 25, 2006 9:34 AM by Rich
Thanks Scott, I will look at the articles you suggested. You are right, it was an error in my code which caused the app_offline.htm page to pop up. I've since corrected that error, but I used Editpad by JG Software (nice little editor I've used for a number of years) so that I could find the error. I'm still learning about all the great things VS 2005 offers. It seems I also made a mistake in my error trapping code, which I fixed. I appreciate you getting back to me with your thoughts and suggestions. I look forward to participating more in your blog. Rich

# re: App_Offline.htm

Thursday, October 26, 2006 5:28 PM by Haakon
Hi, I have a testapplication where I create new profiles in SQL Express. Here is my code: ProfileCommon p = (ProfileCommon)ProfileCommon.Create("jondoe", true); p.FirstName = "Jon"; p.LastName = "Doe"; p.Save(); utskrift.Text = Profile.FirstName + " " + Profile.LastName; Response.Write("finito"); The app_offline.htm keeps beeing generated every time I build my project. Kind regards, Haakon

# re: App_Offline.htm

Saturday, October 28, 2006 12:44 PM by ScottGu

Hi Haakon,

That is pretty odd.  The only reason I could think that there would be this problem is if the database keeps getting re-generated on each attempt.  

Thanks,

Scott

# re: App_Offline.htm

Tuesday, November 14, 2006 7:54 AM by P&#233;ter
Hi, I need some help. I uploaded App_Offline.htm and the site looks stop working. But my CbfCASPNETDB_log.LDF file is locked. I am not able to delete or rename it. Deletion is necessary because CbfCASPNETDB.MDF file was modified and uploaded. Did someone have same experience? Peter

# re: App_Offline.htm

Tuesday, November 14, 2006 1:43 PM by ScottGu

Hi Peter,

I think the problem you are running into is that your SQL Express database is holding the file open.  Unfortunately you'll need to stop/restart the SQL Express process in order to update this file.

Hope this helps,

Scott

# re: App_Offline.htm

Friday, November 17, 2006 11:16 AM by Ezequiel Porta

TIP: The app_offline.htm file must be greater than 512 bytes if you want to MS Ineternet Explorer show this "friendly" error message and not and a 404 Error Message default page.

# re: App_Offline.htm

Thursday, November 30, 2006 1:11 AM by paper shredder

If a hacker gets to place the file on your web root somehow you'll be wondering what happened for quite a while.

# re: App_Offline.htm

Thursday, November 30, 2006 10:07 AM by Rich

Is there a way of getting VS to use a custom made App_Offline.htm file instead of the default one? It would be nice if we could still let VS take care of placing and deleting the file during deploy/publish and still let use choose the message/design displayed to users.

Cheers

# re: App_Offline.htm

Friday, December 01, 2006 12:56 AM by ScottGu

Hi Rich,

Unfortunately the app_offline.htm file that VS creates doesn't support customization I'm afraid.

Sorry about that. :-(

Scott

# re: App_Offline.htm

Friday, December 01, 2006 1:01 AM by ScottGu

Hi Paper,

If a hacker is allowed to download files onto the root of your web you have pretty serious security problems (since they can modify all of your configuration files and deploy code).  So app_offline.htm would be the least of your worries!

Hope this helps,

Scott

# re: App_Offline.htm

Monday, December 11, 2006 1:13 PM by Gunady

Hi, I have tried this feature. But find it a little awkward. If the user is currently navigating inside my site, app_offline.htm will be shown. But if the new user just visit the page (afeter app_offline.htm) has been copied, the user received 404 error page, bot the content of app_offline.htm. How to make it always display the app_offline.htm conent?

# re: App_Offline.htm

Thursday, February 15, 2007 3:05 PM by Plater

Is there plans in the future to make the auto-created app_offline.htm content custimized?

As it stands now, publishing my webapps doesn't take very long, but I would still prefer users to not see the current message inside app_offline.htm.

I see it as allowing a stacktrace to be visible to the end user the way the message is currently setup.

# re: App_Offline.htm

Thursday, February 15, 2007 3:50 PM by Plater

Actually I take that back. I just looked and I *can* in fact customize it. It's just copied from a location under [User Document/Settings  Path]\Application_Data\Microsoft\VisualStudio\8.0\

# re: App_Offline.htm

Thursday, March 01, 2007 11:17 AM by Slaw

Thanks Plater, I was searching my machine in hopes of finding the file *somewhere*.  This is about the only place I didn't look.

# Upgrading DotNetNuke

Tuesday, June 12, 2007 3:09 PM by Erik van Ballegoij

A frequent question in the forums is "How to upgrade my DotNetNuke install".. I thought i'd post a brief guide here for easy ref download the upgrade package of the version you ...

# Drive:Activated 2.0 - the technical side

Saturday, July 28, 2007 11:52 PM by Drive:Activated

This post will concentrate on the technical side of things behind Drive:Activated 2.0. As I mentioned

# Wartungsseite aufschalten

Thursday, February 21, 2008 3:34 PM by TEMPORARY BLOG NAME

Wartungsseite aufschalten

# Using the app_offline.htm in ASP.NET &laquo; Rhonda Tipton&#8217;s WebLog

Pingback from  Using the app_offline.htm in ASP.NET &laquo; Rhonda Tipton&#8217;s WebLog

# [Tips]ASP.NET 2.0でオンライン閉塞を実現するには?

Monday, April 07, 2008 9:09 PM by おぎわら@.NET道場 Blog(わんくま編)

[Tips]ASP.NET 2.0でオンライン閉塞を実現するには?

# app_offline.htm

Monday, April 14, 2008 11:29 AM by DotNetKicks.com

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# Lexapro.

Monday, July 21, 2008 2:05 PM by Lexapro.

Lexapro side effects.

# nelsonmichael : @scottcreynolds http://weblogs.asp.net/scot...

Friday, August 22, 2008 12:34 PM by Twitter Mirror

nelsonmichael : @ scottcreynolds http://weblogs.asp.net/scot...

# aspx page can't be found | WebHost4Life

Sunday, January 18, 2009 1:30 AM by aspx page can't be found | WebHost4Life

Pingback from  aspx page can't be found | WebHost4Life

# Web App - updating question | keyongtech

Sunday, February 15, 2009 5:10 PM by Web App - updating question | keyongtech

Pingback from  Web App - updating question | keyongtech

# Links of the Week

Wednesday, March 04, 2009 1:55 AM by Rick.Stavanja.com

As usual, I've been too busy to blog lately, but I thought I'd try something new; I'll try posting a

# Did You Know: "App_Offline.htm" Takes IIS Website Offline | MIKE

Pingback from  Did You Know: "App_Offline.htm" Takes IIS Website Offline | MIKE

# Secret ASP.NET Technique

Tuesday, August 04, 2009 3:08 PM by Community Blogs

This is cool, both Scott Guthrie and Erik Porter have just blogged this information In ASP.NET 2.0 you

# Putting your ASP.NET Web Application in Maintenance Mode (using ISAPI_Rewrite) &laquo; Lee Kelleher&#8217;s Weblog

Pingback from  Putting your ASP.NET Web Application in Maintenance Mode (using ISAPI_Rewrite) &laquo;  Lee Kelleher&#8217;s Weblog

# Randall Kent &raquo; Taking an ASP.NET site down for maintenace

Tuesday, November 03, 2009 5:00 PM by Randall Kent » Taking an ASP.NET site down for maintenace

Pingback from  Randall Kent &raquo; Taking an ASP.NET site down for maintenace