Thursday, March 7, 2013

How to keep ASP.NET application "alive" ?

There is one event call, Application_End in Global.asax. It happens when IIS application pool is recycled or the application itself is unloaded.
So add one call to self website to make application running again.

        protected void Application_End(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(1000);
            try
            {
                WebClient http = new WebClient();
                string Result = http.DownloadString(yourwebsiteurl);
            }
            catch (Exception ex)
            {
                string Message = ex.Message;
            }
        }