In this tutorial you will learn about different methods used to make applications offline in ASP.NET.
Firstly we need to answer the question why anybody would want to make an application offline? Nowadays internet users expect a website to be up all day and night no matter what. New technologies make it possible almost in 100%, however still there are times when you're forced to make application offline for some time. The reasons might be the following:
- updating your application might require making application offline, especially applying changes to your database usually can cause serious problems when application is still working,
- some resources can't be modified while they are still in use, to access them sometimes you have to turn off your application for a while,
- suppose there is an error in some module of your application, then the whole is also not working the way it was intended. In such situation it's also better to go offline with your application and repair it.
There are a few methods to make an application offline. Take a look at the next part of tutorial and check out which one suits you.
Go offline using IIS manager
IIS (Internet Information Services) is a web server software. IIS manager allows you to manage your server and that includes making application offline. The easiest way to do so is to find your web application on the list, right-click on it and just click "Stop".
However the first solution is not the best one because then your website is simply not working. It's better to create a special page that will inform you users that website is not working with a short explanation why and with estimated time when the website will be up again. Then you just have to go to Http Redirect options in ISS manager and configure it to redirect everyone to a webpage that you just have created.
One of the biggest drawbacks of this solution is that sometimes it is impossible to do so. It is caused because of the fact that some hosting providers don't give you the access to IIS manager. In that case you should try one of the other solutions.
Use <httpRuntime> to go offline
Another way to go offline is to configure web.config file. The following piece of code:
causes that application is not started. Whenever you set attribute enable of httpRuntime to false then the AppDomain object is not created and thus application cannot be started. The <httpRuntime> tag should be within <system.Web> tag like in the following example:
This solution works similarly to stopping your webpabe in ISS server. Web application is simply not working and user that tries to enter your website doesn't know what is happening. The last solution deals with that problem.
Go offline with App_Offline.htm file
If you create a html page with information about your website being offline for a while and name it App_Offline.htm all you have to do is to place this page in server's root directory. Then all requests to your web application will result in displaying content of App_Offline.htm file. It's a very good solution (similar to redirecting to dedicated page in IIS manager) because user gets the feedback and knows why and for how long your web application will be offline.
Take a look at the example of such a App_Offline file:
Code used for this example is listed below:
Closing remarks
In this tutorial you learned about different methods used to make applications offline in ASP.NET. The best solutions are the ones where user gets the feedback - redirecting to a dedicated page from ISS manager or using App_Offline file. However these two solutions require a bit of time needed to create a page with information about website going offline. If you need to turn off your page just for a moment you can use as well other solutions described in this article.