我在我的服务器上设置了自定义错误,我正在重定向到一个页面,如下所示
<customErrors mode="On">
<error statusCode="500" redirect="/servererror/default.aspx" />
</customErrors>
当它到达页面时,servererror/default.aspx
我需要它向我发送一封电子邮件,其中包含exception.message
这是我正在尝试的,但它不起作用
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@email.co.uk"
Errormail.From = "servererror@email.co.uk"
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
任何帮助将非常感激
谢谢
杰米