asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search








Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Taking an ASP.NET 2.0 Application Offline
By John Peterson
Rating: 4.1 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Normally the last thing you want is for your web application to be offline. In the 24/7/365 world of the Internet, users expect your site to be available whenever they want to use it. Many of the improvements in the latest versions of ASP.NET and IIS have helped make this goal a reality, and these days it's not uncommon for sites to achieve upwards of 99.9% uptime. That being said, there are times when it's either desirable or necessary to take an ASP.NET application offline.

    Just because you take an application offline doesn't necessarily mean your site is down. You might be dealing with an application that represents one small part of your site or maybe you've implemented a web farm and requests can be handled by other servers. This article discusses a technique to simplify taking a single application offline. How taking that application down affects your site depends on the site's specific architecture and configuration.

    Why Take an Application Offline?

    There are two main reasons that you would normally want to take your application offline.

    • To make major changes to the application.
    • To gain access to resources that cannot be accessed while in use.

    If you're going to make major changes to your application then it's likely that you don't want users using it in the process. For example, if you're changing the structure of one of your database tables and the associated code, having users access it while those changes are taking place will most likely result in problems.

    Speaking of the database, that brings up the second reason you might want to take your application offline. When an application is actively accessing an Access or SQL Server Express database it locks the files so that they aren't modified by other processes. The problem is that if you need to make changes to those files or replace them, you're not able to until the application releases the lock, and it won't release the lock as long as users are accessing the database.

    In both of 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.

    The app_offline.htm File

    So now that we've decided we want to take an application offline, how do we do it? If we've got access to the server we could stop the web site via the IIS management console, but in most shared hosting scenarios you don't have that kind of access to the server. The other shortcoming of that approach is that many developers publish via FrontPage Server Extensions or WebDAV, both of which need the web site to be running in order to make changes.

    Enter the app_offline.htm file. 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.

    A Sample app_offline.htm File

    For an example of an app_offline.htm file you don't have to look any further then the files that Microsoft ships with Visual Web Developer Express.

    app_offline.htm:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Application Offline</title>
    </head>
    <style>

    div {
        background-color:#ffffcc;
        padding-top:10px;
        padding-bottom:10px;
        padding-left:10px;
        padding-right:10px;
        border-style:solid;
        border-color:Black;
        border-width:1px;
    }

    </style>
    <body>
        <div>
        This application is currently offline. To enable the application, remove the
        app_offline.htm file from the application root directory.
        </div>
    </html>

    When viewed from a browser it looks something like this:

    If you look at the address bar in the screen shot above, you'll notice that I didn't actually request app_offline.htm. I requested the application's default.aspx page but was sent the contents of the app_offline.htm file instead.

    You're free to have the file say whatever you want, but you do want to make sure that it's not too short. Many people have run across an error where IE will display one of its "friendly HTTP error messages" if the file is smaller then 512 bytes.

    For more information on this issue see Scott Guthrie's blog entry: app_offline.htm and working around the "IE Friendly Errors" feature.

    One last thing to note is that, while all requests to .NET files will be redirected to app_offline.htm, static content and classic ASP scripts will continue to be served and run as usual. Just a heads up for those of you running applications that contains a mix of classic ASP and ASP.NET.

    Summary

    While the goal for most sites is to stay up as much as possible, there are times when you need to take an application offline. The new ASP.NET app_offline.htm file provides an extremely convenient way to take an application down when you need to without shutting down the web server. Not only is it simple for a developer to use, it also provides an easy way to let site visitors know what's going on and helps prevent them from getting errors when the application restarts.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Jul 21, 2005 - N-Tier Web Applications using ASP.NET 2.0 and SQL Server 2005 - Part 1
    While the .NET Framework made building ASP.NET applications easier then it had ever been in the past, .NET 2.0 builds on that foundation in order to take things to the next level. This article shows you to how to construct an N-Tier ASP.NET 2.0 Web application by leveraging the new features of ASP.NET 2.0 and SQL Server 2005.
    [Read This Article]  [Top]
    Apr 28, 2005 - New Files and Folders in ASP.NET 2.0
    With the release of ASP.NET 2.0, Microsoft has greatly increased the power of ASP.NET by introducing a suite of new features and functionalities. As part of this release, ASP.NET 2.0 also comes with a host of new special files and folders that are meant to be used to implement a specific functionality. This article examines these new files and folders in detail and provides examples that demonstrate how to utilize them to create ASP.NET 2.0 applications.
    [Read This Article]  [Top]
    Mar 10, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 2, Cont'd
    Alex Homer continues his detailed look at the major changes to the DataSet class. In this part, he looks at two features that allow developers to work with data in a more structured and efficient way when using the DataSet with a SQL Server 2005 database server.
    [Read This Article]  [Top]
    Mar 9, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 2
    Alex Homer continues his detailed look at the major changes to the DataSet class. In this part, he looks at two features that allow developers to work with data in a more structured and efficient way when using the DataSet with a SQL Server 2005 database server.
    [Read This Article]  [Top]
    Mar 3, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 1, Cont'd
    In this article, Alex Homer looks at the changes between the version 1.x and version 2.0 DataSet and their associated classes, showing you how you can take advantage of the new features to improve your applications' capabilities and performance.
    [Read This Article]  [Top]
    Mar 2, 2005 - The DataSet Grows Up in ADO.NET 2.0 - Part 1
    In this article, Alex Homer looks at the changes between the version 1.x and version 2.0 DataSet and their associated classes, showing you how you can take advantage of the new features to improve your applications' capabilities and performance.
    [Read This Article]  [Top]
    Feb 16, 2005 - Writing a Custom Membership Provider for the Login Control in ASP.NET 2.0
    In ASP.NET 2.0 and Visual Studio 2005, you can quickly program custom authentication pages with the provided Membership Login controls. In this article, Dina Fleet Berry examines the steps involved in using the Login control with a custom SQL Server membership database.
    [Read This Article]  [Top]
    Dec 29, 2004 - ClickOnce Deployment in .NET Framework 2.0
    In this article, Thiru Thangarathinam examines .NET 2.0's new ClickOnce deployment technology that is designed to ease deployment of Windows forms applications. This new technology not only provides an easy application installation mechanism, it also eases deployment of upgrades to existing applications.
    [Read This Article]  [Top]
    Dec 15, 2004 - A Sneak Peek at ASP.NET 2.0's Administrative Tools
    With ASP.NET 2.0, Microsoft has made great strides in increasing developer productivity and has made implementing previously complex solutions relatively easy. Where this version of ASP.NET really shines, however, is in its new administrative tools that allow developers to spend less time managing the configuration of the servers and software and more time developing great code.
    [Read This Article]  [Top]
    Nov 17, 2004 - The ASP.NET 2.0 TreeView Control
    Thiru Thangarathinam introduces ASP.NET 2.0's new TreeView control which provides a seamless way to consume and display information from hierarchical data sources. The article discusses this new control in depth and explains how to use this feature rich control in your ASP.NET applications.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers