Sending the emailThe last step is to email me the error. The code to do that is shown below, using my trusty SendEmail function that supports CDONTS, ASPEmail, ASPMail and JMail. View or download the real source code using the icon at the bottom of this page. function Report500100 ( sError )
{
// get the page in error
var sURL = '' + Request.ServerVariables ( "URL" );
// don't send mail while I'm testing on my dev machine..
// or if we're running the test file!
if ( IsDebug ( ) || -1 != sURL.indexOf ( 'Test500' ) )
return;
// make up the message body
var sBody = 'The file "' + sURL + '" generated an Internal Server Error\n\n';
var dateToday = new Date();
sBody += 'Time: "' + dateToday.getHours() + ':' + dateToday.getMinutes() + '".\n';
sBody += sError;
// send the email
SendEmail ( '500.100.Handler', 'BadCode@' + sHostDomain, '', 'Reporting error', sBody );
}
|
Note that you're not referred to this page by IIS, so you don't use HTTP_REFERER to find the page in error. Instead, use Request.ServerVariables ( "URL" ). You get the original page name, not Handle500100.asp as you might expect. I don't bother sending email when running on my local server, which is what the IsDebug() function detects. I'm the one generating the errors, so there would be little point! That's (almost) it. I don't need to describe how to setup IIS to use custom error handling - it's fully described in the IIS help - just browse to your local IISHELP documentation.  |