I'm running IIS on Windows Server 2003, i faced problems with 500 internal server error. I want to detect if any user gets the following error and restart server if it happens.
I just can't find the good way to detect if server returns this error. I tried to detect it by downloading some light page from server in period of time and checking for error, but i don't think this is optimal variant.
Please share some ideas around my task. Thanks in advance.
Best Answer
Restarting IIS because of a 500 response is about the same as cracking an egg with a hefty swing of a sledgehammer. You are not going to solve this problem with a restart, you are going to have to solve your problem by figuring out what is causing the 500 and correcting it. Automatically restarting the server on a 500 is not a resolution to the problem. At best it's a very weak workaround.
If you have a page that is generating a 500 and it's bad enough to require a server restart then you are in a bad way and you should be focusing on determining the cause of the error. Look in the IIS logs for error information. You may need to enable further log fields to get the information required. Turn on detailed error reporting in your application if it's not already enabled.
That said, if you want to detect when a 500 happens you will need to do something like the following:
A good, compact description of the IIS logs can be found in this post. A related snippet:
If you are facing a situation of too many connections then I would still recommend troubleshooting the application, especially for memory leaks. Isolate the problematic application to its own application pool in order to attempt to avoid having to restart the entire server.