Force ASP.NET Apps to Keep-Alive
Force ASP.NET Apps to Keep-Alive
ASP.NET web applications only keep running for as long as there are some
active sessions -- then they shut down until there is another page request.
This means that if your site isn't always getting hits, then it will stop,
and later requests will have to endure the slow startup and recompilation.
It also means that you cannot ever expect your ASP.NET web applications
to periodically perform a background task, since it may not be running.
I have created a GlobalBase class that will attempt to keep-alive your site
by periodically hitting your site -- and raising an event for background tasks.
This builds upon my previous article on pre-compiling all of your web pages,
so that code is included in this article's code, available in both C# and VB.
Note that this is the actual code that I run on my site, WilsonDotNet.com,
and I think you will find that it always performs very well due to this code.
You can download
the WilsonWebCompile.dll and simply set your Global.asax
file to inherit from the Wilson.WebCompile.GlobalBase class -- thats all.
Make sure you place the dll into your bin directory, and you will need to
also set a reference to it in your project file if you are using VS.NET.
You can also override the time in minutes (15) that the keep-alive uses,
which may be necessary if your Sessions are not using the default 20 minutes.
You can also handle the new associated Elapsed event in your Global.asax,
which will allow you to periodically run a background task from ASP.NET.
The event will be fired every 15 minutes, or your override, but you can
easily write some code to wait for the first event raised after Midnight.
Just keep in mind that this solution, like the other, is mostly a "hack"
and can not possibly ever guarantee your web application will be running.
Author Bio
Paul Wilson is a software architect in Atlanta, currently with a medical device company.
He specializes in Microsoft technologies, including .NET, C#, ASP, SQL, COM+, and VB.
His
WilsonWebForm
Control allows Multiple Forms and Non-PostBack Forms in ASP.NET.
He is a Microsoft MVP in ASP.NET and is also recognized as an ASPFriend's
ASPAce/ASPElite.
He is a moderator on Microsoft's
ASP.NET Forums, as well as one of the top posters.
He is certified in .NET (MCAD), as well as also holding the MCSD, MCDBA, and MCSE.
Please visit his website,
www.WilsonDotNet.com,
or email him at
Paul@WilsonDotNet.com.