I frequently observe that may sites and applications do not have a Global.asax file. One sweet use of such a file is the ability to keep a site appearing well behaved to users and the ability to throttle load the moment any component starts to fail due to load, network issues or whatever.
- First, you NEVER want a site to vomit .Net/C# error messages. Not only is it not professional, the information shown can sometime be used to hack the site.
- Second, if components are failing due to load or unexpected problems, you really want to tell the users to go away and come back later. The problem is knowing when to send users away.
First we add a global error trap – if you forgot to do a try/catch somewhere in your code – fear not, this will handle it!
So when an error occurs, the user will be redirected to the offlinepage AND a cookie added that will last for 15 minutes.
Now we use another event to make sure that any attempt for this user to connect again is gracefully and politely refused.
We actually overdid the testing by not only checking for the cookie (which should have expired), but checking the datetime if the cookie is present (incase something goes odd with the browser handling of cookies).
So what happens? Users are denied access on the first error. If a component is timing out – that’s fine, the load will be quickly trimmed to the volume that can be handled without error. No crashing servers. No ugly error messages. A well behaved website!
P.S. The offline page should be a html page (unless localization is an issue) so it has minimal load on the IIS Server.