views:

12

answers:

1

I have set up custom error on my server and i'm redirecting to a page as shown below

<customErrors mode="On"> 
   <error statusCode="500" redirect="/servererror/default.aspx" /> 
</customErrors>

When it gets to the page servererror/default.aspx I need it to send an e-mail to me with the exception.message

Here's what i'm trying but it won't work

Sub Page_load(ByVal sender As Object, ByVal e As EventArgs)

     Dim LastError As Exception
     Dim ErrMessage As String

     LastError = Server.GetLastError()


        ErrMessage = LastError.Message


Dim Errormail = New MailMessage

     'Send email to me
     Errormail.To           = "[email protected]"

     Errormail.From         = "[email protected]"
     Errormail.Subject      = "Server Error Alert"
     Errormail.BodyFormat   = MailFormat.Text
     Errormail.Priority     = MailPriority.Normal
     Errormail.Body         = ErrMessage

     SmtpMail.SmtpServer    = "localhost"

     SmtpMail.Send(Errormail)

     Server.ClearError()
End Sub

Any help would be much appreciated

Thanks

Jamie

+1  A: 

Look here: http://stackoverflow.com/q/343014/448100

you need to add the redirectmode:

<customErrors mode="On" redirectMode="ResponseRewrite"> 
   <error statusCode="500" redirect="/servererror/default.aspx" /> 
</customErrors>
ibram
I'm trying to do it without using the Global.asax page though
Jamie Taylor
Thanks that works
Jamie Taylor