The recent web site always reported "timer_connection" error, resulting in the site used by the application pool due to too many errors to stop running, the site also appeared the service Unvaliable, unable to visit, on the Internet to check a lot of information, the result is very frustrating, This problem has been bothering me for a long time, has not been resolved, and later colleagues sent an article to let me have a new solution, although not fundamentally solve this error, but can quickly empty and restore the specified application pool
Don't say more, look at this method, the main is to create a connection (such as you want to monitor the site of an address), if you can access this page to explain the site application pool is not a problem, if not access, that is, will be an error, then we can call the following method, to empty and restart the application pool, The code is as follows:
public void Restartapppool ()
{
System.Net.HttpWebRequest request = (HttpWebRequest) webrequest.create (Sys Tem. Configuration.ConfigurationSettings.AppSettings
["WebFile"]. ToString ());
Request. KeepAlive = false;
Try
{
System.Net.HttpWebResponse response = (HttpWebResponse) request. GetResponse ();
Response. Close ();
catch
{
DirectoryEntry root = new DirectoryEntry ("iis://localhost/w3svc/apppools/" + System.Configuration.ConfigurationSettings.AppSettings
["AppPoolName"]. ToString ());
Root. Invoke ("Start", null);
Root.commitchanges ();
Addeventlog ("Restart application pool in:" +datetime.now.tolongtimestring ());
Root. Close ();
}
}
Here's one thing to note, DirectoryEntry need to refer to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.DirectoryServices.dll
Also using System.Net
Instead, I created a Windows service to check the status of the application pool regularly.
Also, when you create Windows service, do not forget to set account to local System in the setup Process Control (ServiceProcessInstaller1) property, otherwise you will be prompted when you install the service You enter username and password, the following figure
At this point you need to create a Windows account before installing the service, and you need to add the user you created before by "Log on as a service" in the policy, and of course it's cumbersome to do this, so be sure to set account to local System to avoid this problem in the installation. I have met this problem before, and finally have to search a circle on the internet to understand what is going on, I hope you encountered this problem is to help you oh.