【发布时间】:2011-09-26 06:21:42
【问题描述】:
使用 UpdatePanel 时,我在自定义错误页面中没有看到真正的错误。在我的 Global.asax 中,我有以下代码:
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
'Get the exception
Dim lastError = Server.GetLastError()
If lastError IsNot Nothing Then
Dim ex As Exception = lastError.GetBaseException()
If ex IsNot Nothing Then
'Log the error
If Log.IsErrorEnabled Then
log4net.ThreadContext.Properties("method") = ex.TargetSite.Name
log4net.ThreadContext.Properties("userId") = User.Current.UserName
Log.Error(ex.Message, ex)
End If
End If
End If
End Sub
如果我查看日志或设置断点,我可以看到我遇到了超时问题。然后我有以下代码将用户发送到错误页面并显示错误:
<script language="javascript" type="text/javascript">
function EndRequestHandler(sender, args) {
if (args.get_error() != undefined) {
// Let the framework know that the error is handled,
// so it doesn't throw the JavaScript alert.
args.set_errorHandled(true);
var errorMessage = args.get_error().message.replace(/</gi, "<").replace(/>/gi, ">");
// If there is, show the custom error.
window.location = _root + 'ShowError.aspx?error=' + encodeURI(errorMessage)
}
}
</script>
但是我从 args.get_error() 得到的错误是这样的:
Sys.WebForms.PageRequestManagerServerErrorException: 发生未知错误时 在服务器上处理请求。 从返回的状态码 服务器是:500
我要怎么做才能让超时错误显示到错误页面?
【问题讨论】:
-
另外,我有 customErrors mode="On" 如果我添加 defaultRedirect="ShowError.aspx" 状态码从 500 变为 0,但我仍然收到错误。
标签: javascript asp.net ajax webforms error-handling