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