Ayer vi que me linkaron desde Error500.net, pues bien, recordé que hay una historia muy interesante que aun no he explicado. Se trata de tener controlados los errores que se producen de ASP, o más bien los errores 500, que son errores de sintaxis, o en ejecución que no habíamos controlado, evidentemente estos errores no deben de llegar al “usuario”, ya que puede haber información comprometida en ella.
Lo mejor que podemos hacer es crear una página de error personalizada. Esto lo encontré en el support de microsfoft, pero para mí me era insuficiente la información que me prestaba, para poder realizar un buen seguimiento del error, así que hice algunas modificaciones, añadí lo que me interesaba, lo puse en una función, y habilite un envío de mail con el error en el Body, de este modo siempre que se produjera un error, me llegaría un mail, con la descripción completa.
Os dejo aquí lo que necesitáis en un zip: error500.zip
Lo descomprimís en vuestro root o donde queráis, aquí hay dos ficheros, uno lo he llamado working.asp, que es el que invocamos desde el IIS (ahora explico como), y el otro es el fichero con las funciones.
Explico un poco el código y lo que yo he puesto:
Working.asp – Aquí solo mostramos el mensaje de error si queremos, o un mensaje personalizado:
<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”1252″%>
<!–#include file=”function.asp”–>
<title>working</title>
</head>
<body>
<%
dim chivato,mens
Chivato=1′cambiar esto para que se vea el mensaje de error o no
mens=getLastError()’obtenemos el error en la variable mens
sendErrorMail(mens)’enviamos el mail si queremos
%>
<div id=”error”>Im working in this! sorry<br> Try it again in few minutes or go to the <a href=’/’ >Home page</a></div>
</body>
</html>
Function.asp:
<% Option Explicit
Function getLastError()’funcion para obtener el error
dim h
h=”"
On Error Resume Next
Response.Clear
Dim objError
Set objError = Server.GetLastError()
‘todo esto es un copy
h=h & “<h2 align=’center’>ASP 500 Error</h2><p align=’center’>An error occurred processing the page you requested.<br>Please see the details below for more information.</p><div align=’center’><center><table>”
If Len(CStr(objError.ASPCode)) > 0 Then
h=h & “<tr><th nowrap align=’left’ valign=’top’>IIS Error Number</th><td align=’left’ valign=’top’>” & objError.ASPCode & “</td></tr>”
End If
If Len(CStr(objError.Number)) > 0 Then
h=h & “<tr> <th nowrap align=’left’ valign=’top’>COM Error Number</th><td align=’left’ valign=’top’>” &objError.Number & ” (0x” & Hex( objError.Number) & “)” & “</td></tr>”
End If
If Len(CStr(objError.Source)) > 0 Then
h=h & “<tr> <th nowrap align=’left’ valign=’top’>Error Source</th><td align=’left’ valign=’top’>” &objError.Source& “</td> </tr>”
End If
If Len(CStr(objError.File)) > 0 Then
h=h & “<tr> <th nowrap align=’left’ valign=’top’>File Name</th><td align=’left’ valign=’top’>” &objError.File& “</td></tr>”
End If
If Len(CStr(objError.Line)) > 0 Then
h=h & “<tr> <th nowrap align=’left’ valign=’top’>Line Number</th><td align=’left’ valign=’top’>” & objError.Line& “</td></tr>”
End If
If Len(CStr(objError.Description)) > 0 Then
h=h & “<tr><th nowrap align=’left’ valign=’top’>Brief Description</th> <td align=’left’ valign=’top’>” & objError.Description & “</td> </tr>”
End If
If Len(CStr(objError.ASPDescription)) > 0 Then
h=h & “<tr> <th nowrap align=’left’ valign=’top’>Full Description</th><td align=’left’ valign=’top’>” & objError.ASPDescription & “</td> </tr>”
End If
‘aquí vienen mis modificaciones, recojo todos los parametros que se le han pasado tanto por query como por form, creo que es una info super valiosa
h=h&”<tr> <th nowrap align=’left’ valign=’top’>Request.form values:</th><td align=’left’ valign=’top’>”
for each actual in request.form
h=h& actual &”=”& request.form(actual)&”<br>”
next
h=h&”</td> </tr>”
h=h&”<tr> <th nowrap align=’left’ valign=’top’> Request.Querystring values:</th><td align=’left’ valign=’top’>”
for each actual in request.QueryString
h=h& actual &”=”& request.QueryString(actual)&”<br>”
next
‘Variables del servidor (podeis poner las que querais a mi me gustan estas)
h=h&”</td> </tr>”
h=h&”<tr> <th nowrap align=’left’ valign=’top’>Request.ServerVariables values:</th><td align=’left’ valign=’top’>”
h=h&”LOCAL_ADDR=”& request.ServerVariables(“LOCAL_ADDR”)&”<br>”
h=h&”REMOTE_ADDR=”& request.ServerVariables(“REMOTE_ADDR”)&”<br>”
h=h&”REMOTE_HOST=”& request.ServerVariables(“REMOTE_HOST”)&”<br>”
h=h&”PATH_INFO=”& request.ServerVariables(“PATH_INFO”)&”<br>”
h=h&”SCRIPT_NAME=”& request.ServerVariables(“SCRIPT_NAME”)&”<br>”
h=h&”URL=”& request.ServerVariables(“URL”)&”<br>”
h=h&”PATH_TRANSLATED=”& request.ServerVariables(“PATH_TRANSLATED”)&”<br>”
h=h&”HTTP_REFERER=”& request.ServerVariables(“HTTP_REFERER”)&”<br>”
h=h&”</td> </tr>”
h=h & “</table></center></div>”
getLastError=h
end function
function sendErrorMail(er)’un envio de email normal y corriente
if er<>”" then
dim myMail
Set myMail=CreateObject(“CDO.Message”)
myMail.Subject=”Error ASP”
myMail.From=”error@gmail.com”
myMail.To=”yourmail@gmail.com”
myMail.HTMLBody = er
myMail.Configuration.Fields.Item (” http://schemas.microsoft.com/cdo/configuration/sendusing”)=2
myMail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpserver “)=”yourdomain”
myMail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpserverport “) =25
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
end if
end function
%>
Configurando el IIS :
| a. | Abra el Administrador de servicios Internet en el MMC. |
| b. | Expanda su Sitio Web predeterminado. |
| c. | Haga clic con el botón secundario en la carpeta Scripts y seleccione Propiedades. |
| d. | Haga clic en la ficha <B>Errores personalizados</B>. |
| e. | Avance, resalte el error HTTP, 100 500, y seleccione Modificar propiedades. |
| f. | Asegúrese de que Tipo de mensaje está establecido en dirección URL. |
| g. | Cambia la dirección URL ” / error500/working.asp ” (sin las comillas). |
| h. | Haga clic en Aceptar hasta que vuelva al MMC. |
De este modo ya se lanzaría el error automáticamente, cuando se produzca.
Un saludo
Recomendados:

Hola,
muchas gracias por tu ayuda!! estoy intentando implementarlo, pero debo adaptarlo ya que mi servidor web no tiene el mismo componente asp mail que el que tú utilizas.
Tengo una pregunta: qué significan las líneas
myMail.Configuration.Fields.Item (” http://schemas.microsoft.com/cdo/configuration/sendusing”)=2
myMail.Configuration.Fields.Item (”http://schemas.microsoft.com/cdo/configuration/smtpserver “)=”yourdomain”
myMail.Configuration.Fields.Item (”http://schemas.microsoft.com/cdo/configuration/smtpserverport “) =25
He intentado acceder a las páginas por sí solas, pero no lo permite.
Gracias de antemano por tu interés!!
buenas! son datos de configuracion para el servidor de correo ;)
[...] No muestres los errores de código, y controla los errores del 50o [...]