I recently started using GoDaddy for hosting some of my websites as I developed a CMS system that I wanted to confirm played well on their systems.
One snag I ran in to was setting up Custom Error Pages, not just simply displaying the error message intead of the default IIS message – actually displaying a page of my own devising so I could have it send me an email to let me know the site had experienced an error.
Configuring custom 404 pages is simple and is done from within the GoDaddy control panel but there was no option for server errors (500 errors) so I contacted GoDaddy and got this fairly unhelpful response:
Thank you for contacting Online Support.
I understand you need assistance with trying to have a custom page to process errors. This process is going to be possible, however you are going to need to make the changes inside of you web.config file. Since this has to deal with 3rd party scripting we would not be able to help with the scripting of the web.config. The process is only going to be able to completed in a web.config file, nothing inside of our interface will help with what you are trying to accomplish.
Please let us know if we can assist you in any other way.
So effectively they are saying ‘I know the answer but I’m not going to tell you’, despite the fact I’ve seen them help others (although we do not support custom scripting, I did take look at your Web.config file to ensure you had added the code required for IIS 7 to display the errors).
In the end after scouring a few different threads I cam up with the following, simply ensure that your web.config file contains the following:
A Sample ASP VBScript Error Handler
The error handler below is pretty primitive but worked for my needs – it gathers only the most useful debugging information server object (line number, error description, file name, IP address, etc.), it then checks for any submitted querystring or posted values and finally it lists the name and value of any session variables at the time of the error.
Now the temptation is to simply generate and show the error whenever your website encounters a problem but this exposes key information that could help launch an attack against your website, as well as giving real time feedback to those crafting attacks.
Generally I put restrictions in place so that the error details are only displayed in the page if the IP address of the visitor matches the IP address of one of my offices OR if the visitor is currently ‘logged in’ (assuming the project I’m working on has some sort of authentication system).
A Better Way
Additionally, I also have the script send an email to me any time an error is generated – this is a great way of finding out detailed information about errors other users are experiencing. In some cases this has allowed me to fix an error before a user has even had time to report it to me.
Server Error Example
Server 500 Error
We're very sorry but there has been an unexpected error on the website.<% Set myErrorObject = server.GetLastError() errorHTML = "
Error Summary" & vbCrLf IF myErrorObject.ASPCode <> "" THEN errorHTML = errorHTML & "
ASP Code: " & myErrorObject.ASPCode & "" & vbCrLf IF myErrorObject.Source <> "" THEN errorHTML = errorHTML & "
Source: " & myErrorObject.Source & "" & vbCrLf IF myErrorObject.File <> "" THEN errorHTML = errorHTML & "
FileName: " & myErrorObject.File & "" & vbCrLf IF myErrorObject.Line <> "" THEN errorHTML = errorHTML & "
LineNumber: " & myErrorObject.Line & "" & vbCrLf IF myErrorObject.Description <> "" THEN errorHTML = errorHTML & "
Description: " & myErrorObject.Description & "" & vbCrLf IF myErrorObject.ASPDescription <> "" THEN errorHTML = errorHTML & "
ASP Description: " & myErrorObject.ASPDescription & "" & vbCrLf errorHTML = errorHTML & "
Time of error: " & time & " on " & date & "" IF Request.ServerVariables("REMOTE_ADDR") <> "" THEN errorHTML = errorHTML & "
IP Address: " & Request.ServerVariables("REMOTE_ADDR") & "" & vbCrLf errorHTML = errorHTML & "
Query String Contents" & vbCrLf FOR EACH queryStringObject IN REQUEST.QUERYSTRING errorHTML = errorHTML & "
" & queryStringObject & ": " & Request.QueryString(queryStringObject) & "" & vbCrLf NEXT errorHTML = errorHTML & "
Form (Post) Contents" & vbCrLf FOR EACH formObject IN REQUEST.FORM errorHTML = errorHTML & "
" & formObject & ": " & Request.Form(formObject) & "" & vbCrLf NEXT errorHTML = errorHTML & "
Session Variable Contents" & vbCrLf FOR EACH currentSessionVariable in Session.Contents errorHTML = errorHTML & "
" & currentSessionVariable & ": " & Session(currentSessionVariable) & "" & vbCrLf NEXT 'CALL SENDEMAILFUNCTION ("[email protected]", "[email protected]","Error on Website", errorHTML) 'IF SESSION("myLoginSessionVariable") OR Request.ServerVariables("remote_addr") = "22.214.171.124" THEN RESPONSE.WRITE(errorHTML) %>%MINIFYHTMLe459651a99ea347dfa2c3dc2dd1a00744%%MINIFYHTMLe459651a99ea347dfa2c3dc2dd1a00745%