Magic of App_offline.htm File in ASP.Net

Who should read this article

This article is for all IT professionals involved in the complete life cycle of the project, especially for professionals involved in the deployment stage of SDLC.

Intro

In today's world, the customer is the heart of any organization and nobody is allowed to stop the application, even for a second without notifying the user. There are situations where we need to upgrade the production code with a new release and want to display a message to the user, like “site is under maintenance”. The best way to do this is using an app_offline.htm. ASP.Net 2.0+ provided a fantastic functionality that brings the site down and redirects the user automatically to the message page “site is under maintenance".

How it works

The ASP.Net runtime checks the root of the application on the server for an “app_offline.htm” file and if it exists then it stops processing the new requests for the application and redirects the user to the “app_offline.htm” file to notify the user about the change.

runtime checks

To do this, you need to create a temp file, name it “app_offline” with “.htm” extension, load it into the root directory of the application, unload the content of the application from the server and remove the “app_offline.htm” file after loading the application back to the server. Until the time you are loading new content of the application then the user will be redirected to the app_offline.htm file. Once you remove the file, IIS will load the application again and start processing the request to the application as normal.

Customizing the app_offline.htm file

You can place any valid HTML content within the file that you want to display to the user.

content

Note: There is no upper limit on the size of the file but you need to ensure that you provide at least 512 bytes in the file so that all browsers can process it. If you don't want to display any content, you can place some dummy content and comment it to by the browser's limit restriction.

When to use app_offline.htm file

You can use this file as a feature in the following scenarios:

  1. You want to replace large content of the application and you don't want new requests for the application in the middle of the content upload.

  2. Help you to unlock the application files without resetting the ISS.

  3. Many automatic publishing tools or options also use this file.

The Publish feature of Visual Studio uses this file

Yes, the publish feature of Visual Studio can also upload this file before unloading your application.

Also, you can customize the file used by publish and to do that, you need to find the path of the file on your disk and change it with the customize copy of the file. Normally, the location of the file used in publish differs depending on the version of the Visual Studio you are using.

C:\Users\USERNAME\AppData\Roaming\Microsoft\VisualStudio\[VS 8.0/9.0/10/11/12/13]/app_offline.htm


Similar Articles