Receive notification when errors occurs

Discussion in 'ASP General' started by Bruno G., Nov 4, 2004.

  1. Bruno G.

    Bruno G. Guest

    Hello!

    Is it possible for IIS to send some sort of notification when an ASP
    error occurs on a page?

    I can see them in the web logs, but I was wondering if there was a way
    to receive an email or some other alert...

    I thought about using CDO Send Mail, but this object is often what
    cause the error in the first place.

    Any suggestion?

    Thanks in advance.

    Bruno G.
     
    Bruno G., Nov 4, 2004
    #1
    1. Advertising

  2. Yes, by implemeting a custom "500" page for your site or application in IIS.
    Then you can have an ASP page handle the 500 errors with code such as this:



    <%
    Option Explicit

    Response.Clear
    Response.Status = 500

    Dim sUrlRequested, sRedirect, sPath
    Dim aVars, aPostData, aCookies, aQuerystring






    Function GetErrorInfo
    Dim aErrorInfo(1,13)
    Dim oError
    Set oError = Server.GetLastError

    aErrorInfo(0,0) = "ASP Code" : aErrorInfo(1,0) = oError.ASPCode
    aErrorInfo(0,1) = "ASP Description" : aErrorInfo(1,1) =
    oError.ASPDescription
    aErrorInfo(0,2) = "Description" : aErrorInfo(1,2) = oError.Description
    aErrorInfo(0,3) = "Category" : aErrorInfo(1,3) = oError.Category
    aErrorInfo(0,4) = "Number" : aErrorInfo(1,4) = oError.Number
    aErrorInfo(0,5) = "Source" : aErrorInfo(1,5) = oError.Source
    aErrorInfo(0,6) = "File" : aErrorInfo(1,6) = oError.File
    aErrorInfo(0,7) = "Line" : aErrorInfo(1,7) = oError.Line
    aErrorInfo(0,8) = "Querystring" : aErrorInfo(1,8) = Request.Querystring
    On Error Resume Next
    aErrorInfo(0,9) = "Form Data" : aErrorInfo(1,9) = Request.Form
    If Err.Number <> 0 Then aErrorInfo(0,9) = "(binary data)"
    On Error Goto 0
    aErrorInfo(0,10) = "All HTTP" : aErrorInfo(1,10) = "<textarea
    style=""width: 410px; height=100px; font: 8pt verdana;"">" &
    Request.ServerVariables("ALL_HTTP") & "</textarea>"
    aErrorInfo(0,11) = "Remote Address" : aErrorInfo(1,11) =
    Request.ServerVariables("REMOTE_ADDR")
    aErrorInfo(0,12) = "Description" : aErrorInfo(1,12) =
    Request.ServerVariables("REMOTE_HOST")
    aErrorInfo(0,13) = "Request Date" : aErrorInfo(1,13) = FormatDateTime(Now,
    1) & " " & FormatDateTime(Now, 3)

    ' "Safen" form data and all HTTP

    If Len(aErrorInfo(1,9)) > 50 Then aErrorInfo(1,9) = "&nbsp;<textarea
    style=""width: 410px; height=100px; font: 8pt verdana;"">" & aErrorInfo(1,9)
    & "</textarea>"
    If Len(aErrorInfo(1,10)) > 50 Then aErrorInfo(1,10) = "&nbsp;<textarea
    style=""width: 410px; height=100px; font: 8pt verdana;"">" &
    aErrorInfo(1,10) & "</textarea>"


    GetErrorInfo = aErrorInfo
    End Function




    sPath = Replace(sUrlRequested, "http://" &
    Request.ServerVariables("SERVER_NAME"), "")


    Call SendAlert(sUrlRequested, sRedirect)
    Call General500()
    Call DumpInfo()



    %>


    <% Sub General500() %>

    <strong>Oops! An error has occurred, and the page you requested
    cannot be loaded.</strong><br />
    The page you requested is unavailable at the moment. An alert has been
    sent to the
    webmaster and this should be corrected soon. Please check back later.

    <% End Sub %>

    <%
    Sub DumpInfo()
    Dim i, aErrors, sBGColor
    aErrors = GetErrorInfo
    %>
    <table width="100%" bgcolor="#000000" cellpadding="0" cellspacing="0">
    <tr bgcolor="#FFFFFF">
    <td align="center"><strong>Error Information</strong></td>
    </tr>

    <tr>
    <td>
    <table width="100%" align="center" cellpadding="3" cellspacing="1">
    <% For i = 0 To UBound(aErrors, 2)
    If i Mod 2 = 0 Then
    sBGColor = "#FFFFFF"
    Else
    sBGColor = "#EEEEEE"
    End If
    %>
    <tr bgcolor="<%=sBGColor%>">
    <td width="120" valign="top" align="right"><%=aErrors(0,i)%>:</td>
    <td><font size="1"><%=aErrors(1,i)%></font></td>
    </tr>
    <% Next %>
    </table>
    </td>
    </tr>
    </table>
    <br />
    <% End Sub %>


    <%
    Function GetServerVariables()
    Dim aVars(), sVar, i
    i = 0
    For Each sVar in Request.ServerVariables
    Redim Preserve aVars(1,i)
    aVars(0,i) = sVar
    aVars(1,i) = Request.ServerVariables(sVar)
    Next
    GetServerVariables = aVars
    End Function


    Function GetQuerystring()
    Dim aVars, sName, i
    GetQuerystring = ""
    i = 0
    If Len(Request.Querystring) > 0 Then
    For Each sName In Request.Querystring
    Redim Preserve aVars(1,i)
    aVars(0,i) = sName
    aVars(1,i) = Request.Querystring(sName)
    Next
    GetQuerystring = aVars
    End If
    End Function


    %>
    <% Response.End %>







    <%


    Sub SendAlert(URL, Redirect)

    Dim sUrlRequested, sReferer, sPath
    Dim oCDO, sMessage, aErrorInfo, i

    sReferer = Request.ServerVariables("HTTP_REFERER")


    sMessage = "Dear Webmaster," & vbCrlf & vbCrLf
    sMessage = sMessage & "The following page request was made on the
    [sitename], but the page generated an error. Please check the code for
    coder error." & vbCrLf & vbCrLf
    sMessage = sMessage & "URL Requested: " & URL & vbCrLf
    sMessage = sMessage & "Referring URL: " & sReferer & vbCrLf
    sMessage = sMessage & "Requester IP : " &
    Request.ServerVariables("REMOTE_ADDR") & vbCrLf
    sMessage = sMessage & "Requested ID : " &
    Request.ServerVariables("AUTH_USER") & vbCrLf & vbCrLf
    sMessage = sMessage & String(50,"-") & vbCrLf
    sMessage = sMessage & "Debug Info:" & vbCrLf & vbCrLf
    aErrorInfo = GetErrorInfo
    For i = 0 To UBound(aErrorInfo, 2)
    sMessage = sMessage & aErrorInfo(0,i) & ":" & vbCrLf & aErrorInfo(1,i) &
    vbCrLf & vbCrLf
    Next

    sPath = Replace(URL, "http://" & Request.ServerVariables("SERVER_NAME"),
    "")







    Set oCDO = Server.CreateObject("CDO.Message")
    oCDO.From = "webserver@mydomain"
    oCDO.To = "me@mydomain"
    oCDO.Subject = "500 Error on Website - " &
    Request.ServerVariables("REMOTE_ADDR")
    oCDO.TextBody = sMessage
    oCDO.Send
    Set oCDO = Nothing

    End Sub


    %>






    Ray at work





















    "Bruno G." <> wrote in message
    news:...
    > Hello!
    >
    > Is it possible for IIS to send some sort of notification when an ASP
    > error occurs on a page?
    >
    > I can see them in the web logs, but I was wondering if there was a way
    > to receive an email or some other alert...
    >
    > I thought about using CDO Send Mail, but this object is often what
    > cause the error in the first place.
    >
    > Any suggestion?
    >
    > Thanks in advance.
    >
    > Bruno G.
    >
     
    Ray Costanzo [MVP], Nov 4, 2004
    #2
    1. Advertising

  3. Bruno G.

    Bruno G. Guest

    Thanks for the code... but what if the 500 error was caused by the Send
    method of the CDO.Message object in another ASP page?
    Won't this email fail as well?

    Bruno

    "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
    message news:...
    > Yes, by implemeting a custom "500" page for your site or application in
    > IIS. Then you can have an ASP page handle the 500 errors with code such as
    > this:
    >

    <snipped code>
    >
    > Ray at work
    >
    > "Bruno G." <> wrote in message
    > news:...
    >> Hello!
    >>
    >> Is it possible for IIS to send some sort of notification when an ASP
    >> error occurs on a page?
    >>
    >> I can see them in the web logs, but I was wondering if there was a way
    >> to receive an email or some other alert...
    >>
    >> I thought about using CDO Send Mail, but this object is often what
    >> cause the error in the first place.
    >>
    >> Any suggestion?
    >>
    >> Thanks in advance.
    >>
    >> Bruno G.
    >>

    >
    >
     
    Bruno G., Nov 4, 2004
    #3
  4. Bruno G.

    Jeff Dillon Guest

    So what do you want to happen? Obviously email is out.

    Write to a text file, event log, or database.

    Jeff

    "Bruno G." <> wrote in message
    news:OJpw$...
    > Thanks for the code... but what if the 500 error was caused by the Send
    > method of the CDO.Message object in another ASP page?
    > Won't this email fail as well?
    >
    > Bruno
    >
    > "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
    > message news:...
    > > Yes, by implemeting a custom "500" page for your site or application in
    > > IIS. Then you can have an ASP page handle the 500 errors with code such

    as
    > > this:
    > >

    > <snipped code>
    > >
    > > Ray at work
    > >
    > > "Bruno G." <> wrote in message
    > > news:...
    > >> Hello!
    > >>
    > >> Is it possible for IIS to send some sort of notification when an ASP
    > >> error occurs on a page?
    > >>
    > >> I can see them in the web logs, but I was wondering if there was a way
    > >> to receive an email or some other alert...
    > >>
    > >> I thought about using CDO Send Mail, but this object is often what
    > >> cause the error in the first place.
    > >>
    > >> Any suggestion?
    > >>
    > >> Thanks in advance.
    > >>
    > >> Bruno G.
    > >>

    > >
    > >

    >
    >
     
    Jeff Dillon, Nov 4, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,027
    Mark Goldin
    Jan 17, 2004
  2. Timo
    Replies:
    1
    Views:
    1,743
    bruce barker
    Jan 26, 2004
  3. =?Utf-8?B?QWxpcmV6YSBaaWFp?=

    PreRender Event occurs immediatley after Load event

    =?Utf-8?B?QWxpcmV6YSBaaWFp?=, Feb 9, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,154
    Hans Kesting
    Feb 9, 2004
  4. Tobias Merler
    Replies:
    0
    Views:
    512
    Tobias Merler
    Sep 24, 2003
  5. Philip
    Replies:
    0
    Views:
    273
    Philip
    Feb 22, 2005
Loading...

Share This Page