How to take the asp.net 2.0 application offline when required

Hi

Some time when we want to make major changes to our application or we want to gain the access to the resources that cannot be accessed when the web application is running, we want to take the Application offline.

When we are making some major changes to the web application we do not want the user to use the web application. If the user uses the web application when we are changing the database structure and its related code then it might result in problem.

Some times we might want to take the application offline because we want to access the actively used Access or SQL Server Express database. When an application is actively accessing the database the associated files are locked so that no other process can change them.

We cannot change or replace them till application releases the lock to these files. At this point a good way to remove the lock will be to take the application offline.

Some times we might also want to take the application offline because we have uploaded some corrupted css files or some file which might take a few minutes to update and those files are affection the whole site. At this point it’s good to take the application offline so that the site can be updated before the users see the site.

In these scenarios it's probably better to take the application offline for a few minutes then to try and make the changes with the application online and then be stuck trying to clean up any problems you run into.

So how do we take the application offline? In Asp.Net 2.0 we have a feature with the help of which we can take the application offline. The app_offline.htm file is a special file that ASP.NET 2.0 watches for in the root of an application. If the file exists, then ASP.NET shuts down the application and sends the contents of the file back to the user's browser for any new requests to dynamic pages in the application. This means that users are basically locked out of the application and you're free to make any changes that need to be made before removing the file and letting them back in.

To take the application online again just remove the file from the root of the application.

Hope this helps
Thanks
Vikram


Share this post   Email it

Feedback

Posted on 1/2/2007 8:58:04 PM

what a nice article, plz add this type topic always,beacuse this is the reallife implementation.

Posted on 7/15/2007 6:51:30 AM

Kool stuff..! I was really looking for something like this..
Cheers,
Viks

Posted on 7/15/2007 6:52:46 AM

Great..! I was looking out for something like this..!
Cheers,
Vikram

Posted on 2/20/2009 7:51:25 PM

This is a neat addition but there is a problem when the request is an ajax call .. On an ajax request, the response is the file which indirectly causes a javascript error. We currently are using HttpModule to determine if the app is currently in maintenance or not and it works fine in this scenario since we do a response.redirect. Is there a better way to handle this?

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 

Copyright © 2006 - 2012 Vikram Lakhotia