我在服务器上设置了自定义错误,我正在重定向到如下所示的页面
<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
非常感谢任何帮助
由于
杰米
答案 0 :(得分:1)
看这里: ASP.NET custom error page - Server.GetLastError() is null
您需要添加redirectmode:
<customErrors mode="On" redirectMode="ResponseRewrite">
<error statusCode="500" redirect="/servererror/default.aspx" />
</customErrors>