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:
- Monitor the IIS log
- Monitor the Windows Application event log.
- Write a custom script (client-side) and add it to the custom error page for the 500 errors so that it will notify you
A good, compact description of the IIS logs can be found in this post. A related snippet:
The most valuable log files for IIS6 (and their locations) are:
- HTTP.SYS Error Log -
%windir%\System32\LogFiles\HTTPERR (Default location; configurable)
- IIS Website Log -
%windir%\System32\LogFiles\W3SVC# (Default location; configurable) **
- Event Log (both System and Application)
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.