【发布时间】:2009-11-08 03:09:26
【问题描述】:
我在共享主机上运行我的应用程序。
当我在开发服务器上运行最新更改时,一切正常 - 当我上传时,我看到一般的“发生错误但未显示”消息。
如果我将 web.config 更改为包含
CustomErrors mode="off"
然后我仍然看到相同的错误消息。
我猜我最近的一项更改导致解析 web.config 时出现问题。
有什么方法可以检索此错误的详细信息?我知道的唯一方法是事件日志和服务器日志——我都无法访问。
非常感谢您的任何帮助
这里的代码可以为其他人节省一些时间。将格式化异常详细信息并邮寄。如果 Global.asax 不存在,请添加它。然后更新 Application_Error 方法。
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
Dim ex As Exception = Server.GetLastError().GetBaseException()
Dim ErrMsg As New Text.StringBuilder
While ex IsNot Nothing
ErrMsg.AppendLine(String.Format("Message : {0}", ex.Message))
ErrMsg.AppendLine(String.Format("Source : {0}", ex.Source))
ErrMsg.AppendLine(String.Format("Target : {0}", ex.TargetSite.ToString))
ErrMsg.AppendLine("Stack: ")
ErrMsg.AppendLine(ex.StackTrace)
If ex.InnerException IsNot Nothing Then
ex = ex.InnerException
ErrMsg.AppendLine(">> Inner Exception >>>>>>>>>>>>>>>>>>>>>")
Else
ex = Nothing
End If
End While
Try
Dim Message As New System.Net.Mail.MailMessage
Message.Body = ErrMsg.ToString
Message.Subject = "MPW Error"
Message.To.Add(New MailAddress("EMAIL_ADDRESS_HERE@example.com"))
Dim SMTP As New SmtpClient
SMTP.Send(Message)
Catch FatalEx As Exception
'Write to file, die or re-throw
End Try
End Sub
【问题讨论】:
标签: asp.net web-config shared-hosting