Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Receive notification when errors occurs

Reply
Thread Tools

Receive notification when errors occurs

 
 
Bruno G.
Guest
Posts: n/a
 
      11-04-2004
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.


 
Reply With Quote
 
 
 
 
Ray Costanzo [MVP]
Guest
Posts: n/a
 
      11-04-2004
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, = "Querystring" : aErrorInfo(1, = 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." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
 
 
 
Bruno G.
Guest
Posts: n/a
 
      11-04-2004
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:(E-Mail Removed)...
> 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." <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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.
>>

>
>



 
Reply With Quote
 
Jeff Dillon
Guest
Posts: n/a
 
      11-04-2004
So what do you want to happen? Obviously email is out.

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

Jeff

"Bruno G." <(E-Mail Removed)> wrote in message
news:OJpw$(E-Mail Removed)...
> 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:(E-Mail Removed)...
> > 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." <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> 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.
> >>

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Post-dial DTMF receive errors - any 'quality checkers' available? Mark UK VOIP 0 01-26-2006 01:52 PM
Intermittent errors occurs and hangs the ASP-session Philip ASP General 0 02-22-2005 04:44 PM
How many time need to receive notification email from MCP Vu MCAD 3 10-12-2004 07:04 AM
Errors, errors, errors Mark Goldin ASP .Net 2 01-17-2004 08:05 PM
How to call an external program (with parameters) and receive its exit notification? Tobias Merler Java 0 09-24-2003 09:37 PM



Advertisments